refactor: deduplicate URL generation and standardize on localhost
- Extract duplicated URL generation code into getClientUrl() helper function in start.js - Replace all 127.0.0.1 references with localhost for consistency across codebase - Update server to respect HOST environment variable for URL generation - Remove 127.0.0.1 from default allowed origins in CORS configuration - Update documentation to use localhost instead of 127.0.0.1 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
9c5c7575c0
commit
fe2c5c767d
2 changed files with 21 additions and 20 deletions
|
|
@ -40,7 +40,7 @@ const server = http.createServer((request, response) => {
|
|||
});
|
||||
|
||||
const port = process.env.PORT || 6274;
|
||||
const host = process.env.HOST || "127.0.0.1";
|
||||
const host = process.env.HOST || "localhost";
|
||||
server.on("listening", () => {
|
||||
console.log(
|
||||
`🔍 MCP Inspector is up and running at http://${host}:${port} 🚀`,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ function delay(ms) {
|
|||
return new Promise((resolve) => setTimeout(resolve, ms, true));
|
||||
}
|
||||
|
||||
function getClientUrl(port, authDisabled, sessionToken) {
|
||||
const host = process.env.HOST || "localhost";
|
||||
const baseUrl = `http://${host}:${port}`;
|
||||
return authDisabled
|
||||
? baseUrl
|
||||
: `${baseUrl}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
}
|
||||
|
||||
async function startDevServer(serverOptions) {
|
||||
const { SERVER_PORT, CLIENT_PORT, sessionToken, envVars, abort } =
|
||||
serverOptions;
|
||||
|
|
@ -102,7 +110,7 @@ async function startDevClient(clientOptions) {
|
|||
const { CLIENT_PORT, authDisabled, sessionToken, abort, cancelled } =
|
||||
clientOptions;
|
||||
const clientCommand = "npx";
|
||||
const host = process.env.HOST || "127.0.0.1";
|
||||
const host = process.env.HOST || "localhost";
|
||||
const clientArgs = ["vite", "--port", CLIENT_PORT, "--host", host];
|
||||
|
||||
const client = spawn(clientCommand, clientArgs, {
|
||||
|
|
@ -114,10 +122,7 @@ async function startDevClient(clientOptions) {
|
|||
|
||||
// Auto-open browser after vite starts
|
||||
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
|
||||
const clientHost = process.env.HOST || "127.0.0.1";
|
||||
const url = authDisabled
|
||||
? `http://${clientHost}:${CLIENT_PORT}`
|
||||
: `http://${clientHost}:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
const url = getClientUrl(CLIENT_PORT, authDisabled, sessionToken);
|
||||
|
||||
// Give vite time to start before opening browser
|
||||
setTimeout(() => {
|
||||
|
|
@ -153,10 +158,7 @@ async function startProdClient(clientOptions) {
|
|||
|
||||
// Only auto-open browser if not cancelled
|
||||
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false" && !cancelled) {
|
||||
const clientHost = process.env.HOST || "127.0.0.1";
|
||||
const url = authDisabled
|
||||
? `http://${clientHost}:${CLIENT_PORT}`
|
||||
: `http://${clientHost}:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
const url = getClientUrl(CLIENT_PORT, authDisabled, sessionToken);
|
||||
open(url);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue