簡體   English   中英

Node js連接到Wamp中的端口

[英]Node js connecting to port in Wamp

我試圖在Node.js中創建自己的“服務器”並將其連接到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...");

有人可以以正確的方式幫助我嗎?

格蕾茲·詹斯(Greetz Jens)

我認為,您需要在WAMP服務器的文檔根文件夾中使用此.htaccess文件:

# .htaccess file in document root.
Options +FollowSymLinks -Indexes -MultiViews

<IfModule mod_rewrite.c>

    RewriteRule ^(.+) http://localhost:8888/$1 [P]

</IfModule>

現在,任何HTTP請求(例如http://localhost/any/path/you/want都將重定向到端口8888

當然,您的Apache應該在與8888不同的端口上監聽,您可以保留默認的80端口。

嗯,現在工作正常,我必須在WebStorm編輯器中更改一些設置

http://prntscr.com/9tdako

但是為什么我必須將app.js更改為server.js?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM