-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·95 lines (79 loc) · 3.22 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require('dotenv').config();
// MARK: - Entry point
const Environment = require('./app/environment');
const Ext = require('./app/extension');
const Express = require('express');
const
{
DatabaseManager,
ModelManager,
NotificationManager,
OauthManager,
ServerManager,
SiteManager,
UserManager,
UtilityManager
} = require('./app/manager');
const Cors = require('cors');
// Setup Express app
const app = Express();
// Cors
app.use(Cors());
// Setup routes
app.use('/component', require('./app/controller/component-controller'));
app.use('/data', require('./app/controller/data-controller'));
app.use('/location', require('./app/controller/location-controller'));
app.use('/notification', require('./app/controller/notification-controller'));
app.use('/oauth', require('./app/controller/oauth-controller'));
app.use('/push', require('./app/controller/push-controller'));
app.use('/site', require('./app/controller/site-controller'));
app.use('/user', require('./app/controller/user-controller'));
// Limit access / methods / request types
app.all('', async (req, res, next) =>
{
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers',
"Origin, Accept-Language, X-Requested-With, Content-Type, Accept, Authorization, x-access-token, x-device-id, x-request-source, x-device-service-name, x-device-service-version");
});
const httpServer = app.listen(Environment.PORT);
Ext.print(`HTTP server listening on ${Environment.PORT}`);
// Initialize app
init(httpServer);
/**
Initialize application
@param {HttpServer} httpServer HTTP server
*/
async function init(httpServer)
{
// Setup database connection
const dbMgr = await DatabaseManager.Init();
// Initiate model manager
const modelMgr = await ModelManager.Init();
const mConfiguration = modelMgr.getModel('configuration');
// Initialize utility manager
const utilityMgr = await UtilityManager.Init(modelMgr);
// Initialize site manager
await SiteManager.Init();
// Initalize Websocket server
const serverMgr = await ServerManager.Init(httpServer, async(token) =>
{
return await Ext.validateToken(token);
});
// Initialize notification manager
const mNotification = modelMgr.getModel('notification');
const mSubscribableEvent = modelMgr.getModel('subscribableevent');
const mEventSubscription = modelMgr.getModel('eventsubscription');
const mUser = modelMgr.getModel('user');
const notificationMgr = await NotificationManager.Init( mNotification,
mSubscribableEvent,
mEventSubscription,
mUser,
mConfiguration,
serverMgr,
utilityMgr);
// Initialize oauth manager
const oauthMgr = await OauthManager.Init(modelMgr);
// Initialize user manager
await UserManager.Init(modelMgr, notificationMgr, utilityMgr, oauthMgr, Ext);
}