locadot 1.3.0 โ 1.4.0
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/README.md +2 -2
- package/dist/index.js +2 -2
- package/dist/server.js +30 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ npx locadot host
|
|
|
42
42
|
###### Continuously watches and outputs proxy logs in real time.
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
npx locadot
|
|
45
|
+
npx locadot watch logs
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
##### ๐งน Clear Logs
|
|
@@ -57,7 +57,7 @@ npx locadot clear logs
|
|
|
57
57
|
###### Print the path of logged files used.
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
npx locadot
|
|
60
|
+
npx locadot path logs
|
|
61
61
|
```
|
|
62
62
|
##### ๐ Restart Proxy
|
|
63
63
|
|
package/dist/index.js
CHANGED
|
@@ -32,13 +32,13 @@ async function run() {
|
|
|
32
32
|
.command("host", "Show all hosts.", () => {
|
|
33
33
|
commands_1.default.getRegistry();
|
|
34
34
|
})
|
|
35
|
-
.command("
|
|
35
|
+
.command("watch logs", "Watch log files", () => { }, async (argv) => {
|
|
36
36
|
commands_1.default.watchLogs();
|
|
37
37
|
})
|
|
38
38
|
.command("clear logs", "Clear logs", () => { }, async (argv) => {
|
|
39
39
|
commands_1.default.clearLogs();
|
|
40
40
|
})
|
|
41
|
-
.command("
|
|
41
|
+
.command("path logs", "Show log path", () => { }, async (argv) => {
|
|
42
42
|
commands_1.default.logPath();
|
|
43
43
|
})
|
|
44
44
|
.command("restart", "Restart locadot", () => { }, async (argv) => {
|
package/dist/server.js
CHANGED
|
@@ -37,20 +37,49 @@ class ProxyHandler {
|
|
|
37
37
|
res.writeHead(502, { "Content-Type": "text/html" });
|
|
38
38
|
res.end((0, utils_1.proxyNotFound)(host));
|
|
39
39
|
}
|
|
40
|
-
proxy.web(req, res, {
|
|
40
|
+
proxy.web(req, res, {
|
|
41
|
+
target: `http://localhost:${targetPort}`,
|
|
42
|
+
changeOrigin: true,
|
|
43
|
+
}, (err) => {
|
|
41
44
|
locadot_file_1.default.updateLogs(host || "", "warn", `${err.name}=> ${err.message}`);
|
|
42
45
|
res.writeHead(502);
|
|
43
46
|
res.end("Connection failed. Host not found.");
|
|
44
47
|
});
|
|
45
48
|
};
|
|
49
|
+
const requestUpgrade = (req, socket, head) => {
|
|
50
|
+
const host = req.headers.host?.split(":")[0];
|
|
51
|
+
const targetPort = domainMap[host];
|
|
52
|
+
if (!targetPort) {
|
|
53
|
+
socket.end();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// locadotFile.updateLogs(
|
|
57
|
+
// host || "",
|
|
58
|
+
// "log",
|
|
59
|
+
// `WebSocket upgrade request for ${host} โ localhost:${targetPort}`
|
|
60
|
+
// );
|
|
61
|
+
proxy.ws(req, socket, head, {
|
|
62
|
+
target: `ws://localhost:${targetPort}`,
|
|
63
|
+
ws: true,
|
|
64
|
+
changeOrigin: true,
|
|
65
|
+
headers: {
|
|
66
|
+
host: `localhost:${targetPort}`,
|
|
67
|
+
},
|
|
68
|
+
}, (err) => {
|
|
69
|
+
locadot_file_1.default.updateLogs(host || "", "warn", `WebSocket Error: ${err.name}=> ${err.message}`);
|
|
70
|
+
socket.end();
|
|
71
|
+
});
|
|
72
|
+
};
|
|
46
73
|
const httpsServer = https_1.default.createServer(defaultCert, requestHandler);
|
|
47
74
|
const httpServer = http_1.default.createServer(requestHandler);
|
|
48
75
|
httpsServer.listen(443, () => {
|
|
49
76
|
locadot_file_1.default.updateLogs("๐ HTTPS proxy running on port 443");
|
|
50
77
|
});
|
|
78
|
+
httpsServer.on("upgrade", requestUpgrade);
|
|
51
79
|
httpServer.listen(80, () => {
|
|
52
80
|
locadot_file_1.default.updateLogs("๐ HTTP proxy running on port 80");
|
|
53
81
|
});
|
|
82
|
+
httpServer.on("upgrade", requestUpgrade);
|
|
54
83
|
}
|
|
55
84
|
async startProxy() {
|
|
56
85
|
if (await locadot_file_1.default.getProcessId()) {
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locadot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Secure your local development environment with HTTPS and custom domains like dev.localhost.",
|
|
5
5
|
"homepage": "https://www.npmjs.com/package/locadot",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"locadot": "./dist/index.js"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"dev": "tsx --watch src/index.ts",
|
|
12
|
-
"build": "tsc"
|
|
13
|
-
},
|
|
14
10
|
"repository": {
|
|
15
11
|
"type": "git",
|
|
16
12
|
"url": "git+https://github.com/avinashid/locadot.git"
|
|
@@ -42,5 +38,9 @@
|
|
|
42
38
|
"devDependencies": {
|
|
43
39
|
"tsx": "^4.19.3",
|
|
44
40
|
"typescript": "^5.8.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "tsx --watch src/index.ts",
|
|
44
|
+
"build": "tsc"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|