diff options
Diffstat (limited to 'bin/server.ts')
-rw-r--r-- | bin/server.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/bin/server.ts b/bin/server.ts new file mode 100644 index 0000000..fe0fefb --- /dev/null +++ b/bin/server.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | HTTP server entrypoint | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | | The "server.ts" file is the entrypoint for starting the AdonisJS HTTP | ||
7 | | server. Either you can run this file directly or use the "serve" | ||
8 | | command to run this file and monitor file changes | ||
9 | | | ||
10 | */ | ||
11 | |||
12 | import 'reflect-metadata' | ||
13 | import { Ignitor, prettyPrintError } from '@adonisjs/core' | ||
14 | |||
15 | /** | ||
16 | * URL to the application root. AdonisJS need it to resolve | ||
17 | * paths to file and directories for scaffolding commands | ||
18 | */ | ||
19 | const APP_ROOT = new URL('../', import.meta.url) | ||
20 | |||
21 | /** | ||
22 | * The importer is used to import files in context of the | ||
23 | * application. | ||
24 | */ | ||
25 | const IMPORTER = (filePath: string) => { | ||
26 | if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
27 | return import(new URL(filePath, APP_ROOT).href) | ||
28 | } | ||
29 | return import(filePath) | ||
30 | } | ||
31 | |||
32 | new Ignitor(APP_ROOT, { importer: IMPORTER }) | ||
33 | .tap((app) => { | ||
34 | app.booting(async () => { | ||
35 | await import('#start/env') | ||
36 | }) | ||
37 | app.listen('SIGTERM', () => app.terminate()) | ||
38 | app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate()) | ||
39 | }) | ||
40 | .httpServer() | ||
41 | .start() | ||
42 | .catch((error) => { | ||
43 | process.exitCode = 1 | ||
44 | prettyPrintError(error) | ||
45 | }) | ||