-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.js
37 lines (26 loc) · 1.19 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const vm = require('node:vm');
const fsp = require('node:fs').promises;
const path = require('node:path');
const console = require('./lib/logger.js');
const common = require('./lib/common.js');
const { loadDir, createRouting } = require('./src/loader.js');
const { Server } = require('./src/server.js');
const sandbox = vm.createContext({ console, common });
(async () => {
const applications = await fsp.readFile('.applications', 'utf8');
const appPath = path.join(process.cwd(), applications.trim());
const configPath = path.join(appPath, './config');
const config = await loadDir(configPath, sandbox);
const libPath = path.join(appPath, './lib');
const lib = await loadDir(libPath, sandbox);
const domainPath = path.join(appPath, './domain');
const domain = await loadDir(domainPath, sandbox);
sandbox.db = require('./lib/db.js');
const apiPath = path.join(appPath, './api');
const api = await loadDir(apiPath, sandbox, true);
const routing = createRouting(api);
const application = { path: appPath, sandbox, console, routing, config };
Object.assign(sandbox, { api, lib, domain, config, application });
application.server = new Server(application);
})();