【发布时间】:2014-07-24 08:14:54
【问题描述】:
我要做的是在调用索引路由(即 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");
});
但这没有用。然后我尝试使用co-views(我现在把html文件放到public目录下):
var views = require("co-views");
var render = views("public");
app.all("/", function * (next){
this.status = 200;
this.body = yield render("index.html");
});
但这没有用。
那么谁能告诉我我必须做什么?
【问题讨论】:
标签: javascript node.js koa