index.js:(放置在 server
文件夹内。)
const serve = require('koa-static')
const Koa = require('koa');
const app = new Koa();
app.use(serve(__dirname + './public'));
app.listen(3000);
console.log('listening on port 3000');
我想显示 index.html
,它位于 /public
文件夹中。
当我启动上面的 index.js
时,我在浏览器上看到 Not Found
。
console.log
显示,它引用 index.js
所在的同一文件夹。
更新1:
console.log(__dirname + './public');
显示
/Users/askar/work/react/hub/server./public
,
但我需要/Users/askar/work/react/hub/public
最佳答案
解决方案:
更改自 app.use(serve(__dirname + './public'));
至 app.use(serve('./public'));
引用:https://www.tutorialspoint.com/koajs/koajs_static_files.htm
关于javascript - 如何在 Koa 中指定静态文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42526990/