aboutsummaryrefslogtreecommitdiffstats
path: root/src/internal-server/start.ts
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-09-18 11:15:25 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-18 11:15:25 +0200
commitd4101a48b3eee8b1fb177831aa02a4b4fbec2588 (patch)
treec92f2fbe91197fde8589207463d0d6526b4ff76b /src/internal-server/start.ts
parent5.6.3-nightly.6 [skip ci] (diff)
downloadferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.gz
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.zst
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.zip
chore: convert various files from JS to TS (#1959)
Diffstat (limited to 'src/internal-server/start.ts')
-rw-r--r--src/internal-server/start.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/internal-server/start.ts b/src/internal-server/start.ts
new file mode 100644
index 000000000..392f7cf41
--- /dev/null
+++ b/src/internal-server/start.ts
@@ -0,0 +1,51 @@
1/*
2|--------------------------------------------------------------------------
3| Http server
4|--------------------------------------------------------------------------
5|
6| This file bootstraps Adonisjs to start the HTTP server. You are free to
7| customize the process of booting the http server.
8|
9| """ Loading ace commands """
10| At times you may want to load ace commands when starting the HTTP server.
11| Same can be done by chaining `loadCommands()` method after
12|
13| """ Preloading files """
14| Also you can preload files by calling `preLoad('path/to/file')` method.
15| Make sure to pass a relative path from the project root.
16*/
17
18import fold from '@adonisjs/fold';
19import { Ignitor } from '@adonisjs/ignitor';
20import fs from 'fs-extra';
21import path from 'path';
22import { LOCAL_HOSTNAME } from '../config';
23import { isWindows } from '../environment';
24
25process.env.ENV_PATH = path.join(__dirname, 'env.ini');
26
27export const server = async (userPath: string, port: number) => {
28 const dbPath = path.join(userPath, 'server.sqlite');
29 const dbTemplatePath = path.join(__dirname, 'database', 'template.sqlite');
30
31 if (!fs.existsSync(dbPath)) {
32 // Manually copy file
33 // We can't use copyFile here as it will cause the file to be readonly on Windows
34 const dbTemplate = await fs.readFile(dbTemplatePath);
35 await fs.writeFile(dbPath, dbTemplate);
36
37 // Change permissions to ensure to file is not read-only
38 if (isWindows) {
39 // eslint-disable-next-line no-bitwise
40 fs.chmodSync(dbPath, fs.statSync(dbPath).mode | 146);
41 }
42 }
43
44 // Note: These env vars are used by adonis as env vars
45 process.env.DB_PATH = dbPath;
46 process.env.USER_PATH = userPath;
47 process.env.HOST = LOCAL_HOSTNAME;
48 process.env.PORT = port.toString();
49
50 new Ignitor(fold).appRoot(__dirname).fireHttpServer().catch(console.error);
51};