-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (39 loc) · 1.21 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
38
39
40
41
42
43
'use strict';
const fsp = require('node:fs').promises;
const path = require('node:path');
const config = require('./config.js');
const logger = require(`./logger/${config.logger.name}.js`)(config.logger);
const server =
require(`./transport/${config.apiServer.transport}-${config.apiServer.framework}.js`)({
config: config.apiServer,
console: Object.freeze(logger),
});
const staticServer = require('./static.js')({
console: Object.freeze(logger),
});
const db = require('./db.js')({
config: config.db,
console: Object.freeze(logger),
});
const hash = require('./hash.js')({
config: config.hash,
console: Object.freeze(logger),
});
const sandbox = {
console: Object.freeze(logger),
db: Object.freeze(db),
common: { hash },
};
const apiPath = path.join(process.cwd(), './api');
const routing = {};
(async () => {
const files = await fsp.readdir(apiPath);
for (const fileName of files) {
if (!fileName.endsWith('.js')) continue;
const filePath = path.join(apiPath, fileName);
const serviceName = path.basename(fileName, '.js');
routing[serviceName] = require(filePath)(sandbox);
}
staticServer('./static', config.staticServer.port);
server(routing, config.apiServer.port);
})();