diff options
author | 2019-10-18 20:53:41 +0200 | |
---|---|---|
committer | 2019-10-18 20:53:41 +0200 | |
commit | af506f40edb1c9c339cc86baf40baccf2dc6da62 (patch) | |
tree | d5efae2f9374ee11d645096208424d59812a9a58 /src/server | |
parent | Merge branch 'develop' into local-server (diff) | |
download | ferdium-app-af506f40edb1c9c339cc86baf40baccf2dc6da62.tar.gz ferdium-app-af506f40edb1c9c339cc86baf40baccf2dc6da62.tar.zst ferdium-app-af506f40edb1c9c339cc86baf40baccf2dc6da62.zip |
Develop local server feature
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/config/database.js | 6 | ||||
-rw-r--r-- | src/server/start.js | 31 |
2 files changed, 17 insertions, 20 deletions
diff --git a/src/server/config/database.js b/src/server/config/database.js index 86f18dac5..a413f7050 100644 --- a/src/server/config/database.js +++ b/src/server/config/database.js | |||
@@ -2,11 +2,7 @@ | |||
2 | /** @type {import('@adonisjs/framework/src/Env')} */ | 2 | /** @type {import('@adonisjs/framework/src/Env')} */ |
3 | const Env = use('Env'); | 3 | const Env = use('Env'); |
4 | 4 | ||
5 | // eslint-disable-next-line import/no-extraneous-dependencies | 5 | const dbPath = process.env.DB_PATH; |
6 | const { app } = require('electron'); | ||
7 | const path = require('path'); | ||
8 | |||
9 | const dbPath = path.join(app.getPath('userData'), 'server.sqlite'); | ||
10 | 6 | ||
11 | module.exports = { | 7 | module.exports = { |
12 | /* | 8 | /* |
diff --git a/src/server/start.js b/src/server/start.js index 8a8711a78..34b2cb5fa 100644 --- a/src/server/start.js +++ b/src/server/start.js | |||
@@ -17,24 +17,25 @@ | |||
17 | */ | 17 | */ |
18 | const path = require('path'); | 18 | const path = require('path'); |
19 | const fs = require('fs-extra'); | 19 | const fs = require('fs-extra'); |
20 | // eslint-disable-next-line import/no-extraneous-dependencies | ||
21 | const { app } = require('electron'); | ||
22 | 20 | ||
23 | process.env.ENV_PATH = path.join(__dirname, 'env.ini'); | 21 | process.env.ENV_PATH = path.join(__dirname, 'env.ini'); |
24 | 22 | ||
25 | // Make sure local database exists | ||
26 | const dbPath = path.join(app.getPath('userData'), 'server.sqlite'); | ||
27 | if (!fs.existsSync(dbPath)) { | ||
28 | fs.copySync( | ||
29 | path.join(__dirname, 'database', 'template.sqlite'), | ||
30 | dbPath, | ||
31 | ); | ||
32 | } | ||
33 | |||
34 | const { Ignitor } = require('@adonisjs/ignitor'); | 23 | const { Ignitor } = require('@adonisjs/ignitor'); |
35 | const fold = require('@adonisjs/fold'); | 24 | const fold = require('@adonisjs/fold'); |
36 | 25 | ||
37 | new Ignitor(fold) | 26 | module.exports = (dbPath, port) => { |
38 | .appRoot(__dirname) | 27 | if (!fs.existsSync(dbPath)) { |
39 | .fireHttpServer() | 28 | fs.copySync( |
40 | .catch(console.error); // eslint-disable-line no-console | 29 | path.join(__dirname, 'database', 'template.sqlite'), |
30 | dbPath, | ||
31 | ); | ||
32 | } | ||
33 | |||
34 | process.env.DB_PATH = dbPath; | ||
35 | process.env.PORT = port; | ||
36 | |||
37 | new Ignitor(fold) | ||
38 | .appRoot(__dirname) | ||
39 | .fireHttpServer() | ||
40 | .catch(console.error); // eslint-disable-line no-console | ||
41 | }; | ||