MCPcopy
hub / github.com/continuedev/continue / startHttpServer

Function startHttpServer

packages/fetch/src/fetch.e2e.test.ts:125–169  ·  view source on GitHub ↗

* Start a simple HTTP server for testing

()

Source from the content-addressed store, hash-verified

123 * Start a simple HTTP server for testing
124 */
125async function startHttpServer(): Promise<http.Server> {
126 const server = http.createServer((req, res) => {
127 const url = new URL(req.url!, `http://localhost:${HTTP_PORT}`);
128
129 if (url.pathname === "/json") {
130 res.writeHead(200, { "Content-Type": "application/json" });
131 res.end(
132 JSON.stringify({
133 message: "Hello from HTTP server",
134 method: req.method,
135 }),
136 );
137 } else if (url.pathname === "/headers") {
138 res.writeHead(200, { "Content-Type": "application/json" });
139 res.end(JSON.stringify({ headers: req.headers }));
140 } else if (url.pathname === "/body") {
141 let body = "";
142 req.on("data", (chunk) => {
143 body += chunk.toString();
144 });
145 req.on("end", () => {
146 res.writeHead(200, { "Content-Type": "application/json" });
147 res.end(JSON.stringify({ body, headers: req.headers }));
148 });
149 } else if (url.pathname === "/status/404") {
150 res.writeHead(404, { "Content-Type": "text/plain" });
151 res.end("Not Found");
152 } else if (url.pathname === "/slow") {
153 setTimeout(() => {
154 res.writeHead(200, { "Content-Type": "text/plain" });
155 res.end("Slow response");
156 }, 100);
157 } else {
158 res.writeHead(404);
159 res.end("Not Found");
160 }
161 });
162
163 await new Promise<void>((resolve) => {
164 server.listen(HTTP_PORT, () => resolve());
165 });
166
167 serversToCleanup.push(server);
168 return server;
169}
170
171/**
172 * Start an HTTPS server with given certificates

Callers 1

fetch.e2e.test.tsFile · 0.85

Calls 3

listenMethod · 0.80
onMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected