【发布时间】:2016-04-27 08:43:11
【问题描述】:
我正在使用 Node.js 来运行一个简单的 HTML 服务器。 index.js 文件启动得非常好,但是当您发现问题时,您可以连接它。每当您进行连接时,您都会看到 Cannot GET / 贴满整个网站,仅此而已。
//Vars
var http = require('http');
var express = require("express");
var app = express();
var connect = require("connect");
//Show .html file
app.use(express.static(__dirname + '/public'));
//Port to listen to
app.listen(8080);
//Just for show
const PORT = 8080;
console.log("Server listening on: http://***.***.***.**:%s", PORT);
这是我用于 index.js 的代码,我希望有人能找到我的问题并帮助我解决它。谢谢。 (对不起,如果其他人问过这个问题)
【问题讨论】:
-
您的
/public目录中有什么? -
你不缺
app.get('/',function(req, res){..........})吗? -
@Jacob 有文件
index/index.html和refused/refused.html。我个人曾尝试将 index.js 中定义的目录更改为/public/index/index.html文件,但只会导致另一个Cannot GET /错误。 -
我相信
/会在静态目录中 寻找index.html文件。你有/index/index.html而不是/index.html的事实可能意味着它找不到/的默认文档。 -
@Fabio 我早就把那条线去掉了,我想是我安装的一个节点。