节点js连接到Wamp中的端口
Node js connecting to port in Wamp
我尝试在 Node.js 中创建自己的 "server" 并将其连接到我的 WAMP 端口 8888。
但不知何故,我没有得到任何回复 localhost:8888 页面上的响应,甚至 console.log?
即使我使用不同的端口也没有任何反应...
var http = require('http');
function onRequest(request, response){
console.log("A user made a request" + request.url);
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Here is some data");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server is now running...");
有人能帮我找到正确的方法吗?
你好
詹斯
我想,您的 WAMP 服务器的文档根文件夹中需要这个 .htaccess 文件:
# .htaccess file in document root.
Options +FollowSymLinks -Indexes -MultiViews
<IfModule mod_rewrite.c>
RewriteRule ^(.+) http://localhost:8888/ [P]
</IfModule>
现在任何 HTTP 请求,如 http://localhost/any/path/you/want
都将被重定向到端口 8888
。
当然,您的 Apache 应该监听与 8888
不同的端口,您可以保留默认的 80
端口。
啊,现在可以正常使用了
我不得不在我的 WebStorm 编辑器中更改一些设置
但为什么我必须将 app.js 更改为 server.js?
我尝试在 Node.js 中创建自己的 "server" 并将其连接到我的 WAMP 端口 8888。 但不知何故,我没有得到任何回复 localhost:8888 页面上的响应,甚至 console.log?
即使我使用不同的端口也没有任何反应...
var http = require('http');
function onRequest(request, response){
console.log("A user made a request" + request.url);
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Here is some data");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server is now running...");
有人能帮我找到正确的方法吗?
你好 詹斯
我想,您的 WAMP 服务器的文档根文件夹中需要这个 .htaccess 文件:
# .htaccess file in document root.
Options +FollowSymLinks -Indexes -MultiViews
<IfModule mod_rewrite.c>
RewriteRule ^(.+) http://localhost:8888/ [P]
</IfModule>
现在任何 HTTP 请求,如 http://localhost/any/path/you/want
都将被重定向到端口 8888
。
当然,您的 Apache 应该监听与 8888
不同的端口,您可以保留默认的 80
端口。
啊,现在可以正常使用了 我不得不在我的 WebStorm 编辑器中更改一些设置
但为什么我必须将 app.js 更改为 server.js?