使用koa.js显示静态html文件

JavaScript KoaJS

Tom凯

2020-03-30

我想做的是在调用索引路由(即localhost:3000)时提供index.html文件。

我使用koa-router进行路由,所以我的路由如下所示:

app.all("/", function * (next){
    //Send the file here
});

我试图像这样使用koa-static:

var serve = require('koa-static');
 app.all("/", function * (next){
        serve("index.html");
    });

但这没有用。然后,我尝试使用共同视图(现在将html文件放在公共目录中):

var views = require("co-views");
var render = views("public");
app.all("/", function * (next){
    this.status = 200;
    this.body = yield render("index.html");
});

但这没有用。

谁能告诉我该怎么办?

第3839篇《使用koa.js显示静态html文件》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android