mrpeak
mrpeak

Reputation: 147

Setting up two different static directories in node.js koajs framework

How can I set up two different static directories in node.js koajs framework?

Upvotes: 0

Views: 917

Answers (1)

James Moore
James Moore

Reputation: 1901

Just use the koa-static middleware twice, such as:

'use strict';
let koa   = require('koa'),
    serve = require('koa-static'),
    app   = koa();

app.use(serve(__dirname + '/one'));
app.use(serve(__dirname + '/two'));

app.listen(3000);

If there were two files with the same relative path and name in both folder one and two the file in folder one would be used as the middleware stack will check that location first since it's added to the middleware stack first.

Upvotes: 4

Related Questions