node.js - ExpressJs Serve multiple static folders not working -
i want structure public folder this:
- public - frontend - backend - assets # serve common css, , js static files backend/frontend
if request prefixed /admin want serve backend folder, else frontend folder 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 can't static files assets folder, keeps giving me index.html instead. right approach make works ? thx alot
if understood question correctly, think more way go.
app.use('/admin', express.static('public/backend')); app.use('/', express.static('public/frontend'));
Comments
Post a Comment