MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / startServer

Method startServer

src/app.js:198–230  ·  view source on GitHub ↗
(port, attempt = 0)

Source from the content-addressed store, hash-verified

196 });
197
198 const startServer = (port, attempt = 0) => {
199 let hasStartedListening = false;
200 const server = app.listen(port, host, () => {
201 hasStartedListening = true;
202 this.webServer = server;
203 startupLog(`✅ Web Server running on ${host}:${port}`);
204 startupLog(`Health endpoint: http://${host}:${port}/health`);
205 startupLog(`Ready endpoint: http://${host}:${port}/ready`);
206 });
207
208 server.on('error', (error) => {
209 const errorCode = error?.code || 'UNKNOWN_ERROR';
210 const errorMessage = error?.message || 'Unknown server error';
211
212 if (!hasStartedListening && errorCode === 'EADDRINUSE' && attempt < maxPortRetryAttempts) {
213 const nextPort = port + 1;
214 startupLog(`Port ${port} is already in use. Trying port ${nextPort}...`);
215 setTimeout(() => startServer(nextPort, attempt + 1), 250);
216 return;
217 }
218
219 if (hasStartedListening && errorCode === 'EADDRINUSE') {
220 logger.warn(`Web server reported a duplicate bind warning on ${host}:${port}, but the bot remains online.`);
221 return;
222 }
223
224 logger.error(`❌ Web server error on port ${port} (${errorCode}): ${errorMessage}`);
225
226 if (!hasStartedListening) {
227 process.exit(1);
228 }
229 });
230 };
231
232 startServer(configuredPort, 0);
233 }

Callers

nothing calls this directly

Calls 1

startupLogFunction · 0.90

Tested by

no test coverage detected