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

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -