forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterialized_history_server.js
More file actions
68 lines (56 loc) · 2.6 KB
/
Copy pathmaterialized_history_server.js
File metadata and controls
68 lines (56 loc) · 2.6 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
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
const path = require('path');
const ModuleLogger = require('./server/utils/module_logger');
const PluginManager = require('./src/plugins/PluginManager');
const settings = require('./src/server/utils/server_settings');
let p = settings.get('pluginManager:configPath');
let pluginManager = new PluginManager(path.isAbsolute(p) ? p : path.join(__dirname, p));
PluginManager.instance = {
systemMonitor: pluginManager.resolve('SystemMonitor').createInstance(settings.get('systemMonitor'),
ModuleLogger.getLogger('HFDM.MaterializedHistoryService.SystemMonitor'), 'mh', settings.get('stackName'))
};
let express = require('express');
let app = express();
process.on('unhandledRejection', (err) => {
console.log('Unhandled promise rejection: ' + err);
console.log(err.stack);
});
let allowedHeaders = 'x-ads-token-data, Origin, X-Requested-With, Content-Type, Accept';
let runningOnCloudOS =
process.env.hasOwnProperty('APP_MONIKER') &&
process.env.hasOwnProperty('CLOUDOS_MONIKER');
if (!runningOnCloudOS) {
// When running locally, add the Authorization header to the list of CORS pre-flight
// headers that the browser should allow on cross-origin requests. This is only
// needed for a local deployment when running tests in a Firefox browser because
// it won't otherwise include the Authorization header which the server needs for
// authentication and authorization.
allowedHeaders += ', Authorization';
}
app.use(function(req, res, next) {
// TODO: How should we configure the CORS headers?
// Will this service be called directly by the browser for queries, or will this happen
// through Collaboration server?
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', allowedHeaders);
res.header('Access-Control-Allow-Methods', '');
next();
});
let promise = new Promise( (resolve, reject) => {
// This command line switch is used in the Dockerfile. It's a quick validation of the server
if (process.argv.includes('--checkOnly')) {
console.log('Detected --checkOnly. Exiting...');
process.exit(0);
}
// Start the server
let Server = require('./src/server/server');
let materializedHistoryServer = new Server({ // eslint-disable-line no-unused-vars
app: app,
systemMonitor: PluginManager.instance.systemMonitor
});
materializedHistoryServer.start().then(resolve).catch(reject);
});
module.exports = promise;