-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·71 lines (59 loc) · 2.16 KB
/
server.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
#!/bin/env node
/** modules ================================================= */
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var multer = require('multer');
var methodOverride = require('method-override');
var passport = require('passport');
var expressSession = require('express-session');
var mongoose = require('mongoose');
/** configuration =========================================== */
var os = require('os');
// connect to our mongoDB database
if(os.hostname().indexOf("local") > -1)
{
var db_local = require('./config/db_local')
mongoose.connect(db_local.url);
}
else
{
var db = require('./config/db');
mongoose.connect(db.url);
}
app.use(expressSession({secret: 'mySecretKey'}));
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'ejs');
// Initialize Passport
var initPassport = require('./app/passport/init');
initPassport(passport);
// get all data/stuff of the body (POST) parameters
// parse application/json
app.use(bodyParser.json());
// parse application/vnd.api+json as json
app.use(bodyParser.json({type: 'application/vnd.api+json'}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: true}));
// override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
app.use(methodOverride('X-HTTP-Method-Override'));
// for parsing multipart/form-data
app.use(multer());
// set the static files location /public/img will be /img for users
app.use(express.static(__dirname + '/public'));
// Set the environment variables we need.
ipaddress = process.env.OPENSHIFT_NODEJS_IP;
port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
if (typeof ipaddress === "undefined")
{
console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
ipaddress = "127.0.0.1";
}
/** routes ================================================== */
require('./app/routes')(app,passport); // configure our routes
/** start app =============================================== */
// Start the app on the specific interface (and port).
app.listen(port, ipaddress, function ()
{
console.log('%s: Node server started on %s:%d ...', new Date(Date.now()), ipaddress, port);
});