fix: honor HOST environment variable for server binding
- Update src/index.js to use HOST environment variable for main server - Update src/auth/oauth.js to use HOST environment variable for OAuth callback server - Add diagnostic logging to show actual bound address on startup - Update startup banner to reflect correct host URL Co-Authored-By: Claude (gemini-3-flash[1m]) <noreply@anthropic.com>
This commit is contained in:
@@ -141,9 +141,10 @@ export function extractCodeFromInput(input) {
|
|||||||
* Attempt to bind server to a specific port
|
* Attempt to bind server to a specific port
|
||||||
* @param {http.Server} server - HTTP server instance
|
* @param {http.Server} server - HTTP server instance
|
||||||
* @param {number} port - Port to bind to
|
* @param {number} port - Port to bind to
|
||||||
|
* @param {string} host - Host to bind to
|
||||||
* @returns {Promise<number>} Resolves with port on success, rejects on error
|
* @returns {Promise<number>} Resolves with port on success, rejects on error
|
||||||
*/
|
*/
|
||||||
function tryBindPort(server, port) {
|
function tryBindPort(server, port, host = '0.0.0.0') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const onError = (err) => {
|
const onError = (err) => {
|
||||||
server.removeListener('listening', onSuccess);
|
server.removeListener('listening', onSuccess);
|
||||||
@@ -155,7 +156,7 @@ function tryBindPort(server, port) {
|
|||||||
};
|
};
|
||||||
server.once('error', onError);
|
server.once('error', onError);
|
||||||
server.once('listening', onSuccess);
|
server.once('listening', onSuccess);
|
||||||
server.listen(port);
|
server.listen(port, host);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +174,7 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
|
|||||||
let timeoutId = null;
|
let timeoutId = null;
|
||||||
let isAborted = false;
|
let isAborted = false;
|
||||||
let actualPort = OAUTH_CONFIG.callbackPort;
|
let actualPort = OAUTH_CONFIG.callbackPort;
|
||||||
|
const host = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
const promise = new Promise(async (resolve, reject) => {
|
const promise = new Promise(async (resolve, reject) => {
|
||||||
// Build list of ports to try: primary + fallbacks
|
// Build list of ports to try: primary + fallbacks
|
||||||
@@ -180,7 +182,7 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
|
|||||||
const errors = [];
|
const errors = [];
|
||||||
|
|
||||||
server = http.createServer((req, res) => {
|
server = http.createServer((req, res) => {
|
||||||
const url = new URL(req.url, `http://localhost:${actualPort}`);
|
const url = new URL(req.url, `http://${host === '0.0.0.0' ? 'localhost' : host}:${actualPort}`);
|
||||||
|
|
||||||
if (url.pathname !== '/oauth-callback') {
|
if (url.pathname !== '/oauth-callback') {
|
||||||
res.writeHead(404);
|
res.writeHead(404);
|
||||||
@@ -264,14 +266,14 @@ export function startCallbackServer(expectedState, timeoutMs = 120000) {
|
|||||||
let boundSuccessfully = false;
|
let boundSuccessfully = false;
|
||||||
for (const port of portsToTry) {
|
for (const port of portsToTry) {
|
||||||
try {
|
try {
|
||||||
await tryBindPort(server, port);
|
await tryBindPort(server, port, host);
|
||||||
actualPort = port;
|
actualPort = port;
|
||||||
boundSuccessfully = true;
|
boundSuccessfully = true;
|
||||||
|
|
||||||
if (port !== OAUTH_CONFIG.callbackPort) {
|
if (port !== OAUTH_CONFIG.callbackPort) {
|
||||||
logger.warn(`[OAuth] Primary port ${OAUTH_CONFIG.callbackPort} unavailable, using fallback port ${port}`);
|
logger.warn(`[OAuth] Primary port ${OAUTH_CONFIG.callbackPort} unavailable, using fallback port ${port}`);
|
||||||
} else {
|
} else {
|
||||||
logger.info(`[OAuth] Callback server listening on port ${port}`);
|
logger.info(`[OAuth] Callback server listening on ${host}:${port}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
15
src/index.js
15
src/index.js
@@ -46,12 +46,22 @@ if (isFallbackEnabled) {
|
|||||||
export const FALLBACK_ENABLED = isFallbackEnabled;
|
export const FALLBACK_ENABLED = isFallbackEnabled;
|
||||||
|
|
||||||
const PORT = process.env.PORT || DEFAULT_PORT;
|
const PORT = process.env.PORT || DEFAULT_PORT;
|
||||||
|
const HOST = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
|
if (process.env.HOST) {
|
||||||
|
logger.info(`[Startup] Using HOST environment variable: ${process.env.HOST}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Home directory for account storage
|
// Home directory for account storage
|
||||||
const HOME_DIR = os.homedir();
|
const HOME_DIR = os.homedir();
|
||||||
const CONFIG_DIR = path.join(HOME_DIR, '.antigravity-claude-proxy');
|
const CONFIG_DIR = path.join(HOME_DIR, '.antigravity-claude-proxy');
|
||||||
|
|
||||||
const server = app.listen(PORT, () => {
|
const server = app.listen(PORT, HOST, () => {
|
||||||
|
// Get actual bound address
|
||||||
|
const address = server.address();
|
||||||
|
const boundHost = typeof address === 'string' ? address : address.address;
|
||||||
|
const boundPort = typeof address === 'string' ? null : address.port;
|
||||||
|
|
||||||
// Clear console for a clean start
|
// Clear console for a clean start
|
||||||
console.clear();
|
console.clear();
|
||||||
|
|
||||||
@@ -93,7 +103,8 @@ const server = app.listen(PORT, () => {
|
|||||||
║ Antigravity Claude Proxy Server ║
|
║ Antigravity Claude Proxy Server ║
|
||||||
╠══════════════════════════════════════════════════════════════╣
|
╠══════════════════════════════════════════════════════════════╣
|
||||||
║ ║
|
║ ║
|
||||||
${border} ${align(`Server and WebUI running at: http://localhost:${PORT}`)}${border}
|
${border} ${align(`Server and WebUI running at: http://${HOST === '0.0.0.0' ? 'localhost' : HOST}:${PORT}`)}${border}
|
||||||
|
${border} ${align(`Bound to: ${boundHost}:${boundPort}`)}${border}
|
||||||
${statusSection}║ ║
|
${statusSection}║ ║
|
||||||
${controlSection}
|
${controlSection}
|
||||||
║ ║
|
║ ║
|
||||||
|
|||||||
Reference in New Issue
Block a user