我想通过custom.local (通过multicast-dns启用)到达本地服务器( localhost:12345 ,其中12345是随机端口)。 我有控制台日志设置,以确保浏览器中访问这两个地址时,事情正在工作。
我如何结合这两个? 看起来像一个代理是要走的路。 这甚至有可能吗?
我基本上试图在我的Node.js项目中做相当于nginx的代理传递。 这是它在nginx中的样子:
server { server_name custom.local; location / { proxy_pass http://localhost:12345; } }
find一个解决scheme,WOOP WOOP!
我正在使用这个模块 ,但稍微调整了源代码(只是因为我有dynamic端口,因为我觉得它)。
/* jshint undef: true, unused: true, esversion: 6, node: true */ "use strict"; // // GET // PACKAGES import express from "express"; import http from "http"; import local from "./server/local"; const n = express(); n.get("/", (req, res) => { res.send("Welcome home"); }); // // LAUNCH const server = http.createServer(n); server.listen(0, () => { const port = server.address().port; local.add(port, "custom.local"); });
希望这也能帮助你,未来的互联网search者! :D不要让负面人士在其他SE网站把你打倒。 :虚拟拳头碰撞: