This repository was archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapplication.js
More file actions
47 lines (39 loc) · 1.44 KB
/
application.js
File metadata and controls
47 lines (39 loc) · 1.44 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
'use strict';
var express = require('express')
, log = require('fh-bunyan').getLogger(__filename)
, mbaasApi = require('fh-mbaas-api')
, mbaasExpress = mbaasApi.mbaasExpress()
, mbaasSync = require('fh-rest-sync-proxy')
, app = module.exports = express();
// Note: the order which we add middleware to Express here is important!
app.use('/sys', mbaasExpress.sys([]));
app.use('/mbaas', mbaasExpress.mbaas);
// Note: important that this is added just before your own Routes
app.use(mbaasExpress.fhmiddleware());
// Important that this is last!
app.use(mbaasExpress.errorHandler());
// This maps MBaaS Service guids to URLs during local development
process.env.FH_USE_LOCAL_DB = true;
process.env.FH_SERVICE_MAP = JSON.stringify({
'afake-service-guid-12345': 'http://127.0.0.1:9001'
});
// Proxy sync calls to an MBaaS Service with guid "fake-service-guid"
// Locally these calls are proxied to http://127.0.0.1:9001
var serviceSync = mbaasSync({
guid: 'afake-service-guid-12345',
timeout: 20000
});
serviceSync.initDataset('users', {
// Place the usual mbaasApi.sync options here
sync_frequency: 60,
logLevel: 'warn'
}, function (err) {
if (err) {
throw err;
}
var port = process.env.FH_PORT || process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || 8001;
var host = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';
app.listen(port, host, function() {
log.info('App started at: %s on port: %s', new Date(), port);
});
});