MCPcopy Create free account
hub / github.com/VisActor/vchart-mcp-server / createBaseHttpServer

Function createBaseHttpServer

src/utils/httpServer.ts:115–153  ·  view source on GitHub ↗
(
  port: number,
  endpoint: string,
  handlers: RequestHandlers
)

Source from the content-addressed store, hash-verified

113 * Creates a base HTTP server with common functionality
114 */
115export function createBaseHttpServer(
116 port: number,
117 endpoint: string,
118 handlers: RequestHandlers
119): http.Server {
120 const httpServer = http.createServer(async (req, res) => {
121 // Handle CORS for all requests
122 handleCORS(req, res);
123
124 // Handle OPTIONS requests
125 if (req.method === 'OPTIONS') {
126 res.writeHead(204).end();
127 return;
128 }
129
130 // Handle common endpoints like health and ping
131 if (handleCommonEndpoints(req, res)) {
132 return;
133 }
134
135 // Pass remaining requests to the specific handler
136 try {
137 await handlers.handleRequest(req, res);
138 } catch (error) {
139 console.error(`Error in ${handlers.serverType} request handler:`, error);
140 res.writeHead(500).end('Internal Server Error');
141 }
142 });
143
144 // Set up cleanup handlers
145 setupCleanupHandlers(httpServer, handlers.cleanup);
146
147 // Start listening and log server info
148 httpServer.listen(port, () => {
149 logServerStartup(handlers.serverType, port, endpoint);
150 });
151
152 return httpServer;
153}

Callers 2

startSSEServerFunction · 0.90
startStreamableServerFunction · 0.90

Calls 4

handleCORSFunction · 0.85
handleCommonEndpointsFunction · 0.85
setupCleanupHandlersFunction · 0.85
logServerStartupFunction · 0.85

Tested by

no test coverage detected