MCPcopy Index your code
hub / github.com/directus/directus / createServer

Function createServer

api/src/server.ts:37–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35const logger = useLogger();
36
37export async function createServer(): Promise<http.Server> {
38 const server = http.createServer(await createApp());
39
40 Object.assign(server, getConfigFromEnv('SERVER_'));
41
42 server.on('request', function (req: http.IncomingMessage & Request, res: http.ServerResponse) {
43 const startTime = process.hrtime();
44
45 const complete = once(function (finished: boolean) {
46 const elapsedTime = process.hrtime(startTime);
47 const elapsedNanoseconds = elapsedTime[0] * 1e9 + elapsedTime[1];
48 const elapsedMilliseconds = elapsedNanoseconds / 1e6;
49
50 const previousIn = (req.socket as any)._metrics?.in || 0;
51 const previousOut = (req.socket as any)._metrics?.out || 0;
52
53 const metrics = {
54 in: req.socket.bytesRead - previousIn,
55 out: req.socket.bytesWritten - previousOut,
56 };
57
58 (req.socket as any)._metrics = {
59 in: req.socket.bytesRead,
60 out: req.socket.bytesWritten,
61 };
62
63 // Compatibility when supporting serving with certificates
64 const protocol = server instanceof https.Server ? 'https' : 'http';
65
66 // Rely on url.parse for path extraction
67 // Doesn't break on illegal URLs
68 const urlInfo = url.parse(req.originalUrl || req.url);
69
70 const info = {
71 finished,
72 request: {
73 aborted: req.aborted,
74 completed: req.complete,
75 method: req.method,
76 url: urlInfo.href,
77 path: urlInfo.pathname,
78 protocol,
79 host: req.headers.host,
80 size: metrics.in,
81 query: urlInfo.query ? qs.parse(urlInfo.query) : {},
82 headers: req.headers,
83 },
84 response: {
85 status: res.statusCode,
86 size: metrics.out,
87 headers: res.getHeaders(),
88 },
89 ip: getIPFromReq(req),
90 duration: elapsedMilliseconds.toFixed(),
91 };
92
93 emitter.emitAction('response', info, {
94 database: getDatabase(),

Callers 1

startServerFunction · 0.70

Calls 12

toBooleanFunction · 0.90
createAppFunction · 0.85
getConfigFromEnvFunction · 0.85
getIPFromReqFunction · 0.85
getDatabaseFunction · 0.85
createLogsControllerFunction · 0.85
startWebSocketHandlersFunction · 0.85
onMethod · 0.80
emitActionMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected