-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathapplication.js
85 lines (73 loc) · 2.52 KB
/
application.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
var $fh = require('fh-mbaas-api');
var express = require('express');
var mbaasExpress = $fh.mbaasExpress();
var cors = require('cors');
var mediator = require('fh-wfm-mediator/lib/mediator');
var bodyParser = require('body-parser');
var raincatcherUser = require('fh-wfm-user/lib/router/mbaas');
var sessionInit = require('./lib/sessionInit');
// list the endpoints which you want to make securable here
var securableEndpoints;
securableEndpoints = ['/hello'];
var app = express();
// Enable CORS for all requests
app.use(cors());
// Note: the order which we add middleware to Express here is important!
app.use('/sys', mbaasExpress.sys(securableEndpoints));
app.use('/mbaas', mbaasExpress.mbaas);
// allow serving of static files from the public directory
app.use(express.static(__dirname + '/public'));
// Note: important that this is added just before your own Routes
app.use(mbaasExpress.fhmiddleware());
app.use('/hello', require('./lib/hello.js')());
app.use('/api', bodyParser.json({limit: '10mb'}));
/**
* Session and Cookie configuration
* This is being consumed in the raincatcher-user mbaas router.
* For available stores, see
* {@link https://github.com/feedhenry-raincatcher/raincatcher-user/tree/master/lib/session/mongoProvider.js}
*/
var sessionOptions = {
store: 'mongo',
config: {
secret: process.env.FH_COOKIE_SECRET || 'raincatcher',
resave: false,
saveUninitialized: true,
cookie: {
secure: process.env.NODE_ENV !== 'development',
httpOnly: true,
path: '/'
}
}
};
// find out mongodb connection string from $fh.db
function run(cb) {
sessionInit(sessionOptions, function(err) {
if (err) {
return cb(err);
}
// List the user fields which you don't want appearing in the authentication response.
// This is being consumed in the raincatcher-user mbaas router.
var authResponseExclusionList = ['password'];
raincatcherUser.init(mediator, app, authResponseExclusionList, sessionOptions, function(err) {
if (err) {
return cb(err);
}
require('./lib/user')(mediator);
// Important that this is last!
app.use(mbaasExpress.errorHandler());
var port = process.env.FH_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8001;
var host = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';
app.listen(port, host, function(err) {
cb(err, port);
});
});
});
}
run(function(err, port) {
if (err) {
console.error(err);
process.exit(1);
}
console.log("App started at: " + new Date() + " on port: " + port);
});