Tuesday 23 May 2017

How can I change the express static path based on the route?

I want to change the static path based on the route. For example (not working):

const app = express();
const appRouter = express.Router();
const adminRouter = express.Router();

appRouter.use(express.static('/path/to/app/static/assets');
adminRouter.use(express.static('/path/to/admin/static/assets');

app.use('/', appRouter);
app.use('/admin', adminRouter);

What I do not want to do is set both paths as static for the entire app:

// the following will expose both paths as static for the entire app
// this does not accomplish what I am trying to do

const app = express();

app.use(express.static('/path/to/app/static/assets');
app.use(express.static('/path/to/admin/static/assets');

Is this possible?



via Dustin

No comments:

Post a Comment