I want to structure my public folder like this:
- public
- frontend
- backend
- assets # to serve common css, and js static files for backend/frontend
if the request is prefixed by /admin then I want to serve backend folder, else then the frontend folder this is what I've tried
app.use(function(req, res, next) {
if (req.url.match('^\/admin')) {
express.static(__dirname + '/public/admin')(req, res, next);
} else {
express.static(__dirname + '/public/frontend')(req, res, next);
}
});
app.use(express.static(__dirname + '/public/assets'));
app.get('*', function(req, res, next) {
if (req.url.match('^\/admin')) {
res.sendFile(__dirname + '/public/admin/app/views/index.html');
} else {
res.sendFile(__dirname + '/public/frontend/app/views/index.html');
}
});
but I can't get the static files from the assets folder, it keeps giving me index.html instead. what is the right approach to make it works ? thx alot
If I understood your question correctly, I think something like this would be more the way to go.
app.use('/admin', express.static('public/backend'));
app.use('/', express.static('public/frontend'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With