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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -