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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -