locadot 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/locadot-file.js +2 -1
- package/dist/server.js +5 -2
- package/package.json +1 -1
package/dist/lib/locadot-file.js
CHANGED
|
@@ -48,10 +48,11 @@ class locadotFile {
|
|
|
48
48
|
delete registry[domain];
|
|
49
49
|
fs_1.default.writeFileSync(constants_1.locadotPath.REGISTRY_FILE, JSON.stringify(registry, null, 2));
|
|
50
50
|
}
|
|
51
|
-
static async watchRegistry() {
|
|
51
|
+
static async watchRegistry(callBackOnChange) {
|
|
52
52
|
return fs_1.default.watch(constants_1.locadotPath.REGISTRY_FILE, async (eventType) => {
|
|
53
53
|
if (eventType === "change") {
|
|
54
54
|
this.updateLogs("🔄 Updated domain mappings.");
|
|
55
|
+
callBackOnChange && callBackOnChange();
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
}
|
package/dist/server.js
CHANGED
|
@@ -18,11 +18,15 @@ class ProxyHandler {
|
|
|
18
18
|
let domainMap = await locadot_file_1.default.getRegistry();
|
|
19
19
|
const proxy = http_proxy_1.default.createProxyServer({});
|
|
20
20
|
const defaultCert = await (0, certs_1.createSSL)("localhost");
|
|
21
|
-
const watcher = await locadot_file_1.default.watchRegistry()
|
|
21
|
+
const watcher = await locadot_file_1.default.watchRegistry(async () => {
|
|
22
|
+
locadot_file_1.default.updateLogs("🔄 Updated domain mappings.");
|
|
23
|
+
domainMap = await locadot_file_1.default.getRegistry();
|
|
24
|
+
});
|
|
22
25
|
process.on("SIGINT", async () => await locadot_file_1.default.destroy(watcher));
|
|
23
26
|
process.on("SIGTERM", async () => await locadot_file_1.default.destroy(watcher));
|
|
24
27
|
const requestHandler = (req, res) => {
|
|
25
28
|
const host = req.headers.host?.split(":")[0];
|
|
29
|
+
locadot_file_1.default.updateLogs(host || "", "log");
|
|
26
30
|
const targetPort = domainMap[host];
|
|
27
31
|
if (!targetPort) {
|
|
28
32
|
res.writeHead(502, { "Content-Type": "text/html" });
|
|
@@ -73,7 +77,6 @@ class ProxyHandler {
|
|
|
73
77
|
await this.startProxy();
|
|
74
78
|
}
|
|
75
79
|
let registry = await locadot_file_1.default.getRegistry();
|
|
76
|
-
console.log(registry);
|
|
77
80
|
if (!fs_1.default.existsSync(constants_1.locadotPath.REGISTRY_FILE)) {
|
|
78
81
|
fs_1.default.writeFileSync(constants_1.locadotPath.REGISTRY_FILE, "{}");
|
|
79
82
|
}
|
package/package.json
CHANGED