小编Sv4*_*443的帖子

NodeJS HTTP - 在80以外的其他端口上侦听

我在Windows上运行XAMPP以在端口80上托管Apache服务器.现在我正在尝试在后台运行NodeJS脚本,但问题是它只能在端口80上侦听.如果确实如此,一切都可以正常运行应该但我不能同时运行Apache,因为Apache优先考虑并且只是为我的网站服务.NodeJS脚本甚至无法收听.

我的问题是:如何切换NodeJS脚本的监听端口(特定端口无关紧要),这样Apache仍然可以在端口80上运行,我可以从世界各地访问NodeJS脚本.

NodeJS代码的一部分:

const http = require('http');

const port = 8080;
const host = '0.0.0.0';




server = http.createServer( function(req, res) {
    if (req.method == 'POST') {
        var body = '';
        req.on('data', function (data) {
            body += data;
            doStuff(body);
        });
        res.writeHead(200, {'Content-Type': 'text'});
        res.end('received request successfully');
    }
    else {
        res.writeHead(405, {'Content-Type': 'text'});
        res.end('not allowed method ' + req.method + ', try again with GET or POST');
    }

})

server.listen(port, null, function(error){
  if(!!error){
    console.log("\x1b[41m%s\x1b[0m", "error while initializing listener on port " + …
Run Code Online (Sandbox Code Playgroud)

apache xampp http node.js

8
推荐指数
1
解决办法
1798
查看次数

如何使用 JavaScript 和 HTML 按钮在 iframe 中打开不同的 URL

所以我想制作一个带有四个 HTML 按钮的菜单的小网站。而不是打开一个全新网站的按钮,我只想要一个 iframe 标签来根据按下的按钮更改它显示的 URL。

请保持简单,我是 HTML、JS 和 CSS 的初学者。谢谢!

html javascript css iframe button

2
推荐指数
2
解决办法
9943
查看次数

标签 统计

apache ×1

button ×1

css ×1

html ×1

http ×1

iframe ×1

javascript ×1

node.js ×1

xampp ×1