/
index.js
34 lines (27 loc) · 970 Bytes
/
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
const path = require('path');
const fs = require('fs');
const { readdirSync, statSync } = require('fs');
const { join } = require('path');
const express = require('express');
const app = express();
const port = 3000;
const spaces = require('./apps/spaces/spaces.json');
const appKeys = (p => readdirSync(p).filter(f => statSync(join(p, f)).isDirectory()))(path.join(__dirname, 'apps'));
app.get('rest/plerion/spaces', function (req, res) {
res.send(spaces);
});
spaces.forEach(space => {
const indexHtml = path.join(__dirname, 'apps', space.app, 'index.html');
if (fs.existsSync(indexHtml)) {
app.get(space.route, function (req, res) {
res.sendFile(indexHtml);
});
}
});
appKeys.forEach(appKey => {
const restRouter = path.join(__dirname, 'apps', appKey, 'router.js');
if (fs.existsSync(restRouter)) {
app.use('/app/' + appKey, require(restRouter));
}
});
app.listen(port, () => console.log(`Plerion listening on port ${port}!`));