aboutsummaryrefslogtreecommitdiffstats
path: root/src/internal-server/start.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal-server/start.js')
-rw-r--r--src/internal-server/start.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/internal-server/start.js b/src/internal-server/start.js
new file mode 100644
index 000000000..adcac0bec
--- /dev/null
+++ b/src/internal-server/start.js
@@ -0,0 +1,53 @@
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*/
17process.env.FERDI_VERSION = '5.4.0-beta.5';
18
19const path = require('path');
20const fs = require('fs-extra');
21const os = require('os');
22
23process.env.ENV_PATH = path.join(__dirname, 'env.ini');
24
25const { Ignitor } = require('@adonisjs/ignitor');
26const fold = require('@adonisjs/fold');
27
28module.exports = async (userPath, port) => {
29 const dbPath = path.join(userPath, 'server.sqlite');
30 const dbTemplatePath = path.join(__dirname, 'database', 'template.sqlite');
31
32 if (!await fs.exists(dbPath)) {
33 // Manually copy file
34 // We can't use copyFile here as it will cause the file to be readonly on Windows
35 const dbTemplate = await fs.readFile(dbTemplatePath);
36 await fs.writeFile(dbPath, dbTemplate);
37
38 // Change permissions to ensure to file is not read-only
39 if (os.platform() === 'win32') {
40 // eslint-disable-next-line no-bitwise
41 fs.chmodSync(dbPath, fs.statSync(dbPath).mode | 146);
42 }
43 }
44
45 process.env.DB_PATH = dbPath;
46 process.env.USER_PATH = userPath;
47 process.env.PORT = port;
48
49 new Ignitor(fold)
50 .appRoot(__dirname)
51 .fireHttpServer()
52 .catch(console.error); // eslint-disable-line no-console
53};