node.js - Serve static file outside of root directory in Koa2 -
i have simple nodejs server uses koa2. serves static files client
folder. however, there config.js
lives outside of client
folder. right client/index.html
file can't serve config.js
.
i'm trying solve adding router should serve config.js
, so:
let configpath = path.resolve(__dirname, '../', 'config.js'); //app.use(serve(configpath)); // doesn't work router.get('/', (ctx) => serve(configpath));
in client/index.html
have script
include.
<script src="config.js"></script>
but browser says still can't find config.js
.
how can make work in koa2?
Comments
Post a Comment