express static 2 different folders

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



express static 2 different folders



Files:



enter image description here
I have two different frontend build apps, each one in own directory - frontApp and frontAdmin and I need to send them on different requests



in routes/index.js


router.get('/', (req, res) =>
res.sendFile('index.html');
);

router.get('/admin', (req, res) =>
res.sendFile('admin/index.html');
);



I tried
in app.js


const frontPath = express.static(path.join(__dirname, '/frontApp'));
const adminPath = express.static(path.join(__dirname, '/frontAdmin'));
app.use(frontPath);
app.use('/admin', adminPath);



At the end i get the app on http://localhost:3000/admin/ but with errors
enter image description here





Are you serving /admin as a route handler or statically. It seems you are trying to do both and you shouldn't be!
– Robert Moskal
Aug 6 at 14:59





then what should i do?
– fleple
Aug 6 at 15:02





To help you solve your problem, we need to see an example of a /main url that expect to work via express.static() and we need to see exactly where the file you want served with that URL is in your file system. Same thing for a /admin url. That's the only way we can help you get things matched up so express.static() does what you want. Also, "doesn't work for me" is NOT a useful description of the problem. You need to describe exactly what happens and what debugging steps you tried. Do you get a 404 error? Do you get no response from the server? Do you get the wrong file?
– jfriend00
Aug 6 at 15:18



/main


express.static()


/admin


express.static()





And, when showing us where the desired files are in the file system, show us exactly where they are located relative to the script that you are putting these routes in.
– jfriend00
Aug 6 at 15:20





Reading your question again, are there just two files you're trying to serve here: main/index.html and admin/index.html? Or are there a whole set of resources for each? Your question does not currently contain enough information for anyone to answer other than guess what you're trying to accomplish.
– jfriend00
Aug 6 at 15:21



main/index.html


admin/index.html




1 Answer
1



Sorry for incorrect question, the problem was in mime type



i did this and it works now


const frontPath = express.static(path.join(__dirname, '/frontApp'));
const adminPath = express.static(path.join(__dirname, '/frontAdmin'));
app.use(frontPath);
app.use(adminPath);
app.use('/admin', adminPath);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS