MCPcopy Create free account
hub / github.com/artsy/force / startServer

Function startServer

src/Server/startServer.ts:14–64  ·  view source on GitHub ↗
(
  app,
  onStart?: () => void,
)

Source from the content-addressed store, hash-verified

12 * cache have a chance to be refactored.
13 */
14export async function startServer(
15 app,
16 onStart?: () => void,
17): Promise<http.Server> {
18 setupExpressErrorHandler(app)
19
20 return new Promise(resolve => {
21 initializeArtsyXapp(() => {
22 const message =
23 NODE_ENV === "development"
24 ? `[Force] Booting on ${APP_URL}... \n`
25 : `\n[Force] Started on ${APP_URL}. \n`
26
27 const server = withGracefulShutdown(http.createServer(app))
28
29 const stopServer = once(() => {
30 server.shutdown(() => {
31 console.log("Closed existing connections.")
32 process.exit(0)
33 })
34 })
35
36 if (KEEPALIVE_TIMEOUT_SECONDS) {
37 console.log(
38 "Setting keepAliveTimeout to " + KEEPALIVE_TIMEOUT_SECONDS + " sec.",
39 )
40 server.keepAliveTimeout = Number(KEEPALIVE_TIMEOUT_SECONDS) * 1000
41 }
42
43 if (HEADERS_TIMEOUT_SECONDS) {
44 console.log(
45 "Setting headersTimeout to " + HEADERS_TIMEOUT_SECONDS + " sec.",
46 )
47
48 // @ts-ignore -- FIXME: Property 'headersTimeout' does not exist on type 'Server & WithShutdown'.
49 server.headersTimeout = Number(HEADERS_TIMEOUT_SECONDS) * 1000
50 }
51
52 // @ts-ignore -- Argument of type 'string' is not assignable to parameter of type 'number'.
53 server.listen(PORT, "0.0.0.0", () => {
54 console.log(message)
55
56 onStart?.()
57
58 resolve(server)
59 })
60
61 process.on("SIGTERM", stopServer)
62 })
63 })
64}

Callers 2

bootFunction · 0.90
startDevServerFunction · 0.85

Calls 3

initializeArtsyXappFunction · 0.90
resolveFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected