()
| 164 | } |
| 165 | |
| 166 | export 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 | } |
no test coverage detected