MCPcopy
hub / github.com/axios/axios / requestHandler

Function requestHandler

sandbox/server.js:75–109  ·  view source on GitHub ↗

* Handles incoming HTTP requests. * * Serves static files like index.html and axios.js, or routes API requests to * handleApiRequest. Responds with 404 for unrecognized paths. * * @param {http.IncomingMessage} req - The HTTP request object. * @param {http.ServerResponse} res - The HTTP respons

(req, res)

Source from the content-addressed store, hash-verified

73 * @param {http.ServerResponse} res - The HTTP response object.
74 */
75function requestHandler(req, res) {
76 req.setEncoding('utf8');
77
78 const parsed = new URL(req.url, 'http://localhost');
79 const pathname = parsed.pathname;
80
81 console.log('[' + new Date() + ']', req.method, pathname);
82
83 if (pathname === '/') {
84 pathname = '/index.html';
85 }
86
87 switch (pathname) {
88 case '/index.html':
89 pipeFileToResponse(res, './client.html', 'text/html');
90 break;
91
92 case '/axios.js':
93 pipeFileToResponse(res, '../dist/axios.js', 'text/javascript');
94 break;
95
96 case '/axios.js.map':
97 pipeFileToResponse(res, '../dist/axios.js.map', 'text/javascript');
98 break;
99
100 case '/api':
101 handleApiRequest(req, res);
102 break;
103
104 default:
105 res.writeHead(404);
106 res.end('<h1>404 Not Found</h1>');
107 break;
108 }
109}
110
111const PORT = 3000;
112

Callers

nothing calls this directly

Calls 3

handleApiRequestFunction · 0.85
endMethod · 0.80
pipeFileToResponseFunction · 0.70

Tested by

no test coverage detected