-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (56 loc) · 1.79 KB
/
app.js
File metadata and controls
70 lines (56 loc) · 1.79 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import path from 'path';
import http from 'http';
import express from 'express';
import { engine as hbs } from 'express-handlebars';
const app = express ();
import configService from './services/config.js';
import appConfig from './settings/app.json' assert { type: 'json' };
import terminal from './services/terminal.js';
import token from './services/token.js';
import assetRegisterService from './services/asset-register.js';
global.config = appConfig;
const terminalInstance = terminal(config);
const tokenInstance = token(config);
const assetRegisterInstance = assetRegisterService(config);
app.engine ( 'handlebars', hbs (
{
defaultLayout: 'main',
helpers : {
json: c => JSON.stringify ( c, null, 4 )
}
}
) );
app.set ( 'view engine', 'handlebars' );
// Index page
app.get ( '/', async ( req, res ) => {
// Check asset register
if ( config.enable_asset_register !== false ) {
// Get asset register hosts
const assetHostsGroup = await assetRegisterInstance.getHosts ();
// Update hosts
config.hosts[ 0 ] = {
...config.hosts[ 0 ],
...assetHostsGroup
};
}
// Decorate updated configs
if ( !global.config.decorated ) {
global.config = configService.decorateAppConfig ( global.config );
}
// Serve the view
return res.render ( 'index', {
layout: false,
config: config
} );
} );
// Static files
app.use ( '/', express.static ( 'public' ) );
// Request new terminal
app.get ( '/open/:id', terminalInstance );
// Generate token
app.get ( '/token/:id', tokenInstance );
// Create server
http.createServer ( app )
.listen ( config.app_port, function () {
console.log ( 'App server listening on: http://localhost:' + config.app_port );
} );