@neuralnomads/codenomad 0.7.2 → 0.7.3
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/index.js
CHANGED
|
@@ -77,10 +77,16 @@ function parsePort(input) {
|
|
|
77
77
|
return value;
|
|
78
78
|
}
|
|
79
79
|
function resolveHost(input) {
|
|
80
|
-
|
|
80
|
+
const trimmed = input?.trim();
|
|
81
|
+
if (!trimmed)
|
|
82
|
+
return DEFAULT_HOST;
|
|
83
|
+
if (trimmed === "0.0.0.0") {
|
|
81
84
|
return "0.0.0.0";
|
|
82
85
|
}
|
|
83
|
-
|
|
86
|
+
if (trimmed === "localhost") {
|
|
87
|
+
return DEFAULT_HOST;
|
|
88
|
+
}
|
|
89
|
+
return trimmed;
|
|
84
90
|
}
|
|
85
91
|
async function main() {
|
|
86
92
|
const options = parseCliOptions(process.argv.slice(2));
|
|
@@ -94,11 +100,12 @@ async function main() {
|
|
|
94
100
|
};
|
|
95
101
|
logger.info({ options: logOptions }, "Starting CodeNomad CLI server");
|
|
96
102
|
const eventBus = new EventBus(eventLogger);
|
|
103
|
+
const isLoopbackHost = (host) => host === "127.0.0.1" || host === "::1" || host.startsWith("127.");
|
|
97
104
|
const serverMeta = {
|
|
98
105
|
httpBaseUrl: `http://${options.host}:${options.port}`,
|
|
99
106
|
eventsUrl: `/api/events`,
|
|
100
107
|
host: options.host,
|
|
101
|
-
listeningMode: options.host
|
|
108
|
+
listeningMode: isLoopbackHost(options.host) ? "local" : "all",
|
|
102
109
|
port: options.port,
|
|
103
110
|
hostLabel: options.host,
|
|
104
111
|
workspaceRoot: options.rootDir,
|
|
@@ -56,6 +56,7 @@ export function createHttpServer(deps) {
|
|
|
56
56
|
done();
|
|
57
57
|
});
|
|
58
58
|
const allowedDevOrigins = new Set(["http://localhost:3000", "http://127.0.0.1:3000"]);
|
|
59
|
+
const isLoopbackHost = (host) => host === "127.0.0.1" || host === "::1" || host.startsWith("127.");
|
|
59
60
|
app.register(cors, {
|
|
60
61
|
origin: (origin, cb) => {
|
|
61
62
|
if (!origin) {
|
|
@@ -77,6 +78,11 @@ export function createHttpServer(deps) {
|
|
|
77
78
|
cb(null, true);
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
// When we bind to a non-loopback host (e.g., 0.0.0.0 or LAN IP), allow cross-origin UI access.
|
|
82
|
+
if (deps.host === "0.0.0.0" || !isLoopbackHost(deps.host)) {
|
|
83
|
+
cb(null, true);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
80
86
|
cb(null, false);
|
|
81
87
|
},
|
|
82
88
|
credentials: true,
|
|
@@ -212,12 +218,12 @@ export function createHttpServer(deps) {
|
|
|
212
218
|
actualPort = address.port;
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
|
-
const displayHost = deps.host === "
|
|
221
|
+
const displayHost = deps.host === "127.0.0.1" ? "localhost" : deps.host;
|
|
216
222
|
const serverUrl = `http://${displayHost}:${actualPort}`;
|
|
217
223
|
deps.serverMeta.httpBaseUrl = serverUrl;
|
|
218
224
|
deps.serverMeta.host = deps.host;
|
|
219
225
|
deps.serverMeta.port = actualPort;
|
|
220
|
-
deps.serverMeta.listeningMode = deps.host === "0.0.0.0" ? "all" : "local";
|
|
226
|
+
deps.serverMeta.listeningMode = deps.host === "0.0.0.0" || !isLoopbackHost(deps.host) ? "all" : "local";
|
|
221
227
|
deps.logger.info({ port: actualPort, host: deps.host }, "HTTP server listening");
|
|
222
228
|
console.log(`CodeNomad Server is ready at ${serverUrl}`);
|
|
223
229
|
return { port: actualPort, url: serverUrl, displayHost };
|
|
@@ -8,7 +8,7 @@ function buildMetaResponse(meta) {
|
|
|
8
8
|
return {
|
|
9
9
|
...meta,
|
|
10
10
|
port,
|
|
11
|
-
listeningMode: meta.host === "0.0.0.0" ? "all" : "local",
|
|
11
|
+
listeningMode: meta.host === "0.0.0.0" || !isLoopbackHost(meta.host) ? "all" : "local",
|
|
12
12
|
addresses,
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -25,6 +25,9 @@ function resolvePort(meta) {
|
|
|
25
25
|
return 0;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
function isLoopbackHost(host) {
|
|
29
|
+
return host === "127.0.0.1" || host === "::1" || host.startsWith("127.");
|
|
30
|
+
}
|
|
28
31
|
function resolveAddresses(port, host) {
|
|
29
32
|
const interfaces = os.networkInterfaces();
|
|
30
33
|
const seen = new Set();
|