Node.js和Express:“无法GET /”静态网站
问题描述:
我正在研究一个小型的Node应用程序,并且工作正常。它需要服务于目录/source
的一些静态文件。Node.js和Express:“无法GET /”静态网站
今天,在电脑重启后,当我访问我的本地网站时,我所得到的全部是Cannot GET /
。自上次工作以来,节点配置中没有任何更改。
var express = require('express'),
app = express(),
path = require('path'),
fs = require('fs');
// Load our static site to start with
app.use(express.static(path.join(__dirname, 'source')));
// Start the node server
app.listen(3000, function() {
var host = this.address().address,
port = this.address().port;
console.log('Serving Atenium at http://%s:%s', host, port);
});
我的文件夹的样子:
|- app/
|-- index.js
|- source/
|-- <static files>
任何想法,为什么这个刚刚停止工作?
答
你可以在这个过程中更新你的express模块吗?我相信在Express 4中,静态内容现在由服务静态中间件库处理,这里可以找到https://github.com/expressjs/serve-static。
+0
尚未更新。我使用Express 4.11.2和上面的代码用于工作。我确实尝试设置'serve-static',我得到了同样的结果。 – jnettik 2015-02-23 20:15:10
是否有'source/index.html'文件或任何东西? – 2015-02-23 18:15:19
是的,'source /'目录有一个'index.html'文件。 – jnettik 2015-02-23 18:21:35
您能否请您证明您的路线定义在哪里? – NarendraSoni 2015-02-24 02:35:32