locadot 1.0.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/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/certs.js +42 -0
- package/dist/index.js +88 -0
- package/dist/utils.js +67 -0
- package/package.json +44 -0
- package/tsconfig.json +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Avinash Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# π locadot
|
|
2
|
+
|
|
3
|
+
Secure your local development environment with **HTTPS** and **custom domains** like `https://dev.localhost`, powered by `mkcert`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## β¨ Features
|
|
8
|
+
|
|
9
|
+
- β
Automatically generates **trusted local SSL certificates**
|
|
10
|
+
- π Reverse proxies `https://your.custom.domain` β `app.localhost`
|
|
11
|
+
- π₯οΈ Works on **Windows**, **macOS**, and **Linux**
|
|
12
|
+
- π οΈ OS-specific guidance for host setup
|
|
13
|
+
- β οΈ Warns and exits if domain isnβt correctly mapped to a local IP
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## π Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx locadot --host dev.localhost --port 3350
|
package/dist/certs.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSSL = createSSL;
|
|
7
|
+
const appdata_path_1 = __importDefault(require("appdata-path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const CERT_PATH = (0, appdata_path_1.default)("locadot");
|
|
11
|
+
const mkcert_1 = require("mkcert");
|
|
12
|
+
async function createSSL(domain) {
|
|
13
|
+
console.log(`π Preparing SSL cert for ${domain}`);
|
|
14
|
+
const KEY_FILE = path_1.default.join(CERT_PATH, domain + ".key");
|
|
15
|
+
const CERT_FILE = path_1.default.join(CERT_PATH, domain + ".pem");
|
|
16
|
+
if (fs_1.default.existsSync(KEY_FILE) && fs_1.default.existsSync(CERT_FILE)) {
|
|
17
|
+
console.log(`π Using existing certificate for ${domain}`);
|
|
18
|
+
const key = fs_1.default.readFileSync(KEY_FILE, "utf-8");
|
|
19
|
+
const cert = fs_1.default.readFileSync(CERT_FILE, "utf-8");
|
|
20
|
+
return { key, cert };
|
|
21
|
+
}
|
|
22
|
+
// Otherwise, generate a new one
|
|
23
|
+
console.log(`π Generating SSL cert for ${domain}`);
|
|
24
|
+
const ca = await (0, mkcert_1.createCA)({
|
|
25
|
+
organization: "Locadot",
|
|
26
|
+
countryCode: "IN",
|
|
27
|
+
state: "DevState",
|
|
28
|
+
locality: "DevTown",
|
|
29
|
+
validity: 365,
|
|
30
|
+
});
|
|
31
|
+
const cert = await (0, mkcert_1.createCert)({
|
|
32
|
+
domains: [domain],
|
|
33
|
+
ca: ca,
|
|
34
|
+
validity: 365,
|
|
35
|
+
organization: "Locadot",
|
|
36
|
+
});
|
|
37
|
+
if (!fs_1.default.existsSync(CERT_PATH))
|
|
38
|
+
fs_1.default.mkdirSync(CERT_PATH, { recursive: true });
|
|
39
|
+
fs_1.default.writeFileSync(KEY_FILE, cert.key);
|
|
40
|
+
fs_1.default.writeFileSync(CERT_FILE, cert.cert);
|
|
41
|
+
return { key: cert.key, cert: cert.cert };
|
|
42
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidLocalhostDomain = isValidLocalhostDomain;
|
|
7
|
+
exports.isDomainRunning = isDomainRunning;
|
|
8
|
+
const https_1 = __importDefault(require("https"));
|
|
9
|
+
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
10
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
11
|
+
const helpers_1 = require("yargs/helpers");
|
|
12
|
+
const certs_1 = require("./certs");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function isValidLocalhostDomain(domain) {
|
|
15
|
+
const localhostPattern = /^(?:[a-zA-Z0-9-]+\.)*localhost$/;
|
|
16
|
+
return localhostPattern.test(domain);
|
|
17
|
+
}
|
|
18
|
+
async function createReverseProxy(targetPort, domain) {
|
|
19
|
+
const proxy = http_proxy_1.default.createProxyServer({});
|
|
20
|
+
const { key, cert } = await (0, certs_1.createSSL)(domain);
|
|
21
|
+
const options = { key, cert };
|
|
22
|
+
const server = https_1.default.createServer(options, (req, res) => {
|
|
23
|
+
const host = req.headers.host;
|
|
24
|
+
if (host !== domain && host !== `${domain}:443`) {
|
|
25
|
+
res.writeHead(502, { "Content-Type": "text/html" });
|
|
26
|
+
res.end((0, utils_1.proxyNotFound)(host));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
proxy.web(req, res, { target: `http://localhost:${targetPort}` }, (err) => {
|
|
30
|
+
console.error("Proxy error:", err);
|
|
31
|
+
res.writeHead(502);
|
|
32
|
+
res.end("Connection failed. Host not found.");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
server.listen(443, () => {
|
|
36
|
+
console.log(`β
HTTPS available at https://${domain}`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function isDomainRunning(domain, port = 443) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
const req = https_1.default.request({
|
|
42
|
+
hostname: domain,
|
|
43
|
+
port,
|
|
44
|
+
method: "HEAD",
|
|
45
|
+
rejectUnauthorized: false, // ignore self-signed certs
|
|
46
|
+
timeout: 1000,
|
|
47
|
+
}, (res) => {
|
|
48
|
+
resolve(true);
|
|
49
|
+
res.destroy();
|
|
50
|
+
});
|
|
51
|
+
req.on("error", () => resolve(false));
|
|
52
|
+
req.on("timeout", () => {
|
|
53
|
+
req.destroy();
|
|
54
|
+
resolve(false);
|
|
55
|
+
});
|
|
56
|
+
req.end();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function run() {
|
|
60
|
+
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
61
|
+
.option("host", {
|
|
62
|
+
alias: "h",
|
|
63
|
+
describe: "Domain to map (must point to 127.0.0.1 in hosts file)",
|
|
64
|
+
demandOption: true,
|
|
65
|
+
type: "string",
|
|
66
|
+
})
|
|
67
|
+
.option("port", {
|
|
68
|
+
alias: "p",
|
|
69
|
+
describe: "Local port to forward to",
|
|
70
|
+
demandOption: true,
|
|
71
|
+
type: "number",
|
|
72
|
+
})
|
|
73
|
+
.usage("Usage: npx local-ssl --host local.dev --port 3350")
|
|
74
|
+
.help().argv;
|
|
75
|
+
if (!isValidLocalhostDomain(argv.host)) {
|
|
76
|
+
console.error("β Invalid domain. Please use a valid localhost domain like dev.localhost, localhost, test.localhost, etc.");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
const isRunning = await isDomainRunning(argv.host);
|
|
80
|
+
if (isRunning) {
|
|
81
|
+
console.error("β Domain already in use. Please choose another domain or stop the existing instance.");
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
const domain = argv.host;
|
|
85
|
+
const port = argv.port;
|
|
86
|
+
createReverseProxy(port, domain);
|
|
87
|
+
}
|
|
88
|
+
run();
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxyNotFound = void 0;
|
|
4
|
+
const proxyNotFound = (host) => `
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="UTF-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
10
|
+
<title>Proxy Error</title>
|
|
11
|
+
<style>
|
|
12
|
+
body {
|
|
13
|
+
background-color: #121212;
|
|
14
|
+
color: #f8d7da;
|
|
15
|
+
font-family: 'Segoe UI', sans-serif;
|
|
16
|
+
margin: 0;
|
|
17
|
+
padding: 20px;
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
min-height: 90vh;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.error-box {
|
|
25
|
+
background-color: #1e1e1e;
|
|
26
|
+
border: 1px solid #d9534f;
|
|
27
|
+
padding: 24px;
|
|
28
|
+
border-radius: 8px;
|
|
29
|
+
max-width: 600px;
|
|
30
|
+
width: 100%;
|
|
31
|
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.error-box code {
|
|
35
|
+
background: #2e2e2e;
|
|
36
|
+
color: #ffd5d5;
|
|
37
|
+
padding: 2px 6px;
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
font-family: monospace;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.error-box a {
|
|
43
|
+
color: #61dafb;
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
font-weight: bold;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.error-box a:hover {
|
|
49
|
+
text-decoration: underline;
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
52
|
+
</head>
|
|
53
|
+
<body>
|
|
54
|
+
<div class="error-box">
|
|
55
|
+
<strong style="color: #ff6b6b;">Connection failed:</strong>
|
|
56
|
+
Proxy does not exist for
|
|
57
|
+
<code>${host}</code>.<br/><br/>
|
|
58
|
+
Please use
|
|
59
|
+
<code>npx locadot --host ${host} --port PORT</code><br/><br/>
|
|
60
|
+
<a href="https://github.com/avinashid/locadot#readme" target="_blank">
|
|
61
|
+
π View on GitHub
|
|
62
|
+
</a>
|
|
63
|
+
</div>
|
|
64
|
+
</body>
|
|
65
|
+
</html>
|
|
66
|
+
`;
|
|
67
|
+
exports.proxyNotFound = proxyNotFound;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "locadot",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Secure your local development environment with HTTPS and custom domains like https://dev.localhost, powered by mkcert.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"local-ssl": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "tsx --watch src/index.ts",
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/avinashid/locadot.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"locadot",
|
|
19
|
+
"https",
|
|
20
|
+
"ssl",
|
|
21
|
+
"https-proxy",
|
|
22
|
+
"localhost",
|
|
23
|
+
"https"
|
|
24
|
+
],
|
|
25
|
+
"author": "avinashid",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/avinashid/locadot/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/avinashid/locadot#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@types/http-proxy": "^1.17.16",
|
|
33
|
+
"@types/yargs": "^17.0.33",
|
|
34
|
+
"appdata-path": "^1.0.0",
|
|
35
|
+
"http-proxy": "^1.18.1",
|
|
36
|
+
"https": "^1.0.0",
|
|
37
|
+
"mkcert": "^3.2.0",
|
|
38
|
+
"yargs": "^17.7.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsx": "^4.19.3",
|
|
42
|
+
"typescript": "^5.8.3"
|
|
43
|
+
}
|
|
44
|
+
}
|