MCPcopy
hub / github.com/directus/directus / startServer

Function startServer

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

Source from the content-addressed store, hash-verified

164}
165
166export async function startServer(): Promise<void> {
167 const server = await createServer();
168
169 const host = env['HOST'] as string;
170 const path = env['UNIX_SOCKET_PATH'] as string | undefined;
171 const port = env['PORT'] as string;
172
173 let listenOptions: ListenOptions;
174
175 if (path) {
176 listenOptions = { path };
177 } else {
178 listenOptions = {
179 host,
180 port: parseInt(port),
181 };
182 }
183
184 server
185 .listen(listenOptions, () => {
186 const protocol = server instanceof https.Server ? 'https' : 'http';
187
188 logger.info(
189 `Server started at ${listenOptions.port ? `${protocol}://${getAddress(server)}` : getAddress(server)}`,
190 );
191
192 process.send?.('ready');
193
194 emitter.emitAction(
195 'server.start',
196 { server },
197 {
198 database: getDatabase(),
199 schema: null,
200 accountability: null,
201 },
202 );
203 })
204 .once('error', (err: any) => {
205 if (err?.code === 'EADDRINUSE') {
206 logger.error(`${listenOptions.port ? `Port ${listenOptions.port}` : getAddress(server)} is already in use`);
207 process.exit(1);
208 } else {
209 throw err;
210 }
211 });
212}

Callers 1

start.tsFile · 0.70

Calls 5

getAddressFunction · 0.85
getDatabaseFunction · 0.85
emitActionMethod · 0.80
createServerFunction · 0.70
sendMethod · 0.45

Tested by

no test coverage detected