【问题标题】:How to specify a static folder in Koa?如何在 Koa 中指定一个静态文件夹?
【发布时间】:2017-07-20 12:00:57
【问题描述】:

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

【问题讨论】:

标签: javascript node.js koa


【解决方案1】:

解决方案:

更改自 app.use(serve(__dirname + './public'));

app.use(serve('./public'));

参考:https://www.tutorialspoint.com/koajs/koajs_static_files.htm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多