【发布时间】:2017-05-27 11:26:51
【问题描述】:
我是 node.js 的新手,我想了解是否可以通过编写 index.html 的 url 来访问 node.js 端口(3000)。我关注this tutorial创建了一个聊天应用,但是我遇到了上面提到的问题。
我希望能够在我的浏览器上编写 localhost/myproject/index.html 而不是 localhost:3000。
我的服务器端 javascript 代码是这样的:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
这里有什么我应该改变的吗?任何帮助将不胜感激。
【问题讨论】:
-
您为什么要以这种方式使用应用程序路由会很有趣?
-
你正在使用哪个网络服务器
-
我使用有 apache 服务器的 WAMP
-
使用 Apache,您可以设置一个反向代理,将请求重定向到 localhost/myproject/* 到 localhost:3000
标签: javascript node.js express socket.io localhost