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
1 changed files with 21 additions and 20 deletions
|
|
@ -104,12 +104,10 @@ const originValidationMiddleware = (
|
|||
|
||||
// Default origins based on CLIENT_PORT or use environment variable
|
||||
const clientPort = process.env.CLIENT_PORT || "6274";
|
||||
const defaultOrigins = [
|
||||
`http://localhost:${clientPort}`,
|
||||
`http://127.0.0.1:${clientPort}`,
|
||||
const defaultOrigin = `http://localhost:${clientPort}`;
|
||||
const allowedOrigins = process.env.ALLOWED_ORIGINS?.split(",") || [
|
||||
defaultOrigin,
|
||||
];
|
||||
const allowedOrigins =
|
||||
process.env.ALLOWED_ORIGINS?.split(",") || defaultOrigins;
|
||||
|
||||
if (origin && !allowedOrigins.includes(origin)) {
|
||||
console.error(`Invalid origin: ${origin}`);
|
||||
|
|
@ -531,7 +529,7 @@ app.get("/config", originValidationMiddleware, authMiddleware, (req, res) => {
|
|||
});
|
||||
|
||||
const PORT = parseInt(process.env.PORT || "6277", 10);
|
||||
const HOST = process.env.HOST || "127.0.0.1";
|
||||
const HOST = process.env.HOST || "localhost";
|
||||
|
||||
const server = app.listen(PORT, HOST);
|
||||
server.on("listening", () => {
|
||||
|
|
@ -544,7 +542,8 @@ server.on("listening", () => {
|
|||
|
||||
// Display clickable URL with pre-filled token
|
||||
const clientPort = process.env.CLIENT_PORT || "6274";
|
||||
const clientUrl = `http://localhost:${clientPort}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
const clientHost = process.env.HOST || "localhost";
|
||||
const clientUrl = `http://${clientHost}:${clientPort}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
console.log(
|
||||
`\n🔗 Open inspector with token pre-filled:\n ${clientUrl}\n`,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue