-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (39 loc) · 1.11 KB
/
index.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';
let fs = require('fs');
let path = require('path');
let log = require('./log');
let app = require('./app');
let route = require('./route');
let properties = require('./properties');
let resolve = require('./resolve');
const PORT = properties.port(8081);
const IP = properties.listen.ip();
const CWD = properties.cwd();
module.exports = {
loadComponents(components) {
if (!components) {
components = [];
try {
for (let entry of fs.readdirSync(CWD)) {
let source = path.join(CWD, entry);
if (fs.statSync(source).isDirectory()) {
try {
components.push(resolve(source));
} catch (e) {
log.error(e, `[begin-server] (FATAL) ERROR READING SOURCE "${source}"`);
process.exit(2);
}
}
}
} catch (e) {
log.error(e, `[begin-server] (FATAL) ERROR READING SOURCE DIRECTORY "${CWD}"`);
process.exit(1);
}
}
components.forEach(route.register);
},
listen() {
app.listen(PORT, IP);
log.info(`[begin-server] http started on port ${PORT}`);
},
};