【发布时间】:2019-07-15 06:20:20
【问题描述】:
我无法设置简单的 Koa 服务器,所以它可以让我在不同的文件夹中拥有 index.html 和 css 文件。同样作为下一步,我想在不同的文件夹中有许多 js 文件。我不知道科阿。请提供帮助。
我曾尝试使用 Can I have koa-static serve assets at a custom (e.g., /static/) path? 中所示的 mount 但它不起作用
const path = require('path');
const Koa = require('koa');
const koaStatic = require('koa-static');
const getPort = require('get-port');
async function runServer() {
const port = await getPort({ port: 3000 });
const app = new Koa();
app.use(koaStatic(path.join(__dirname, '..', 'src/static')));
app.use(koaStatic(path.join(__dirname, '..', 'src/styles')));
app.listen(port);
console.log(`server started at http://localhost:${port}/`);
}
runServer().catch(console.error);
我收到以下错误:GET http://localhost:3000/src/styles/vendor.css net::ERR_ABORTED 404 (Not Found)
我的文件结构如下: 我的项目 ->
src-> components (header.component.js, footer.component.js)
src-> services (service.js)
src-> assets (data.json)
src-> scripts (some-js-files.js)
src-> styles (styles.css)
src-> static (index.html)
我希望应用能够在 localhost:3000 上运行并识别所有路径
【问题讨论】:
标签: javascript file server path koa