I'm using the multicast-dns
node module to attempt making this work.
我正在使用multicast-dns节点模块尝试使其工作。
Looking up custom.local
in the browser gives me the console message I setup, but I'm unable to see my actual server running (which is doing so at localhost:12345
, where 12345
is a dynamic number). I want to be able to see my local server when visiting custom.local
. Is this possible?
在浏览器中查找custom.local给了我设置的控制台消息,但是我无法看到我的实际服务器正在运行(在localhost:12345,其中12345是动态数字)。我希望能够在访问custom.local时看到我的本地服务器。这可能吗?
Here's some code:
这是一些代码:
mdns.on("query", query => {
if (query.questions[0] && query.questions[0].name === "custom.local") {
console.log(query);
mdns.respond({
answers: [
{
name: "custom.local",
type: "SRV",
data: {
port: n.get("p"), // dynamic port
weight: 0,
priority: 10,
target: ip // local IP
}
}, {
name: "custom.local",
type: "A",
data: ip,
ttl: 300
}
]
});
}
});
EDIT: I can connect to my local server just fine, that wasn't an issue.
编辑:我可以很好地连接到我的本地服务器,这不是一个问题。
1 个解决方案
#1
0
Quoting cfreak:
引用cfreak:
You can't put port numbers in DNS. DNS is only for looking up an IP by name. For your browser to see it by the name alone you need a proxy program in front of your service or you need to run the service itself on port 80. Port numbers really shouldn't be dynamic. You should specify it in the setup of your service.
您不能在DNS中输入端口号。 DNS仅用于按名称查找IP。为了让您的浏览器仅通过名称查看它,您需要在服务前面使用代理程序,或者您需要在端口80上运行服务本身。端口号实际上不应该是动态的。您应该在服务的设置中指定它。
That answers my question and offers next steps. Thanks!
这回答了我的问题并提供了后续步骤。谢谢!
UPDATE: Figured out what I was trying to do. Here's some code!
更新:弄清楚我想要做什么。这是一些代码!
FOUND A SOLUTION, WOOP WOOP!
发现一个解决方案,WOOP WOOP!
I'm using this module, but tweaked the source a bit (only because I have dynamic ports, because I feel like it).
我正在使用这个模块,但稍微调整了一下源(仅因为我有动态端口,因为我觉得这样)。
/* jshint undef: true, unused: true, esversion: 6, node: true */
"use strict";
//
// G E T
// P A C K A G E S
import express from "express";
import http from "http";
import local from "./server/local";
const n = express();
n.get("/", (req, res) => {
res.send("Welcome home");
});
//
// L A U N C H
const server = http.createServer(n);
server.listen(0, () => {
const port = server.address().port;
local.add(port, "custom.local");
});
Hope this helps you as well, future Internet searcher! :D Don't let negative folks on other SE sites bring you down. :virtual fist bump:
希望这也有助于您,未来的互联网搜索者! :D不要让其他SE网站上的负面人员让你失望。 :虚拟拳头撞击:
#1
0
Quoting cfreak:
引用cfreak:
You can't put port numbers in DNS. DNS is only for looking up an IP by name. For your browser to see it by the name alone you need a proxy program in front of your service or you need to run the service itself on port 80. Port numbers really shouldn't be dynamic. You should specify it in the setup of your service.
您不能在DNS中输入端口号。 DNS仅用于按名称查找IP。为了让您的浏览器仅通过名称查看它,您需要在服务前面使用代理程序,或者您需要在端口80上运行服务本身。端口号实际上不应该是动态的。您应该在服务的设置中指定它。
That answers my question and offers next steps. Thanks!
这回答了我的问题并提供了后续步骤。谢谢!
UPDATE: Figured out what I was trying to do. Here's some code!
更新:弄清楚我想要做什么。这是一些代码!
FOUND A SOLUTION, WOOP WOOP!
发现一个解决方案,WOOP WOOP!
I'm using this module, but tweaked the source a bit (only because I have dynamic ports, because I feel like it).
我正在使用这个模块,但稍微调整了一下源(仅因为我有动态端口,因为我觉得这样)。
/* jshint undef: true, unused: true, esversion: 6, node: true */
"use strict";
//
// G E T
// P A C K A G E S
import express from "express";
import http from "http";
import local from "./server/local";
const n = express();
n.get("/", (req, res) => {
res.send("Welcome home");
});
//
// L A U N C H
const server = http.createServer(n);
server.listen(0, () => {
const port = server.address().port;
local.add(port, "custom.local");
});
Hope this helps you as well, future Internet searcher! :D Don't let negative folks on other SE sites bring you down. :virtual fist bump:
希望这也有助于您,未来的互联网搜索者! :D不要让其他SE网站上的负面人员让你失望。 :虚拟拳头撞击: