-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (44 loc) · 1.72 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
var path = require('path');
var express = require('express');
var cors = require('cors');
var passport = require('passport');
var app=express();
var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,PATCH,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, cid, user-id, x-auth, Cache-Control, X-Requested-With, *');
if ('OPTIONS' === req.method) {
res.sendStatus(200);
} else {
next();
};
});
app.use(express.static(__dirname + '/public'));
//app.use(express.static(__dirname + '/controllers'));
app.use(require("./controllers/userCtr.js"));
app.use(require("./controllers/all.js"));
app.use(cors()); //authentication if routes does not send correct tocken along
//passportjs middleware
app.use(passport.initialize());
app.use(passport.session());
//adding passport file in here
require('./config/passport')(passport);
//ORM Configurations
var waterlineConfig = require('./config/connections')
, waterlineOrm = require('./config/init').waterlineOrm;
var modelPath = path.join(__dirname, '/models');
require('./config/init')(modelPath);
//ORM Initialization
waterlineOrm.initialize(waterlineConfig, function (err, models) {
if (err) throw err;
db = function (table) { return models['collections'][table]; };
db.collections = models.collections;
db.connections = models.connections;
app.listen(3000);
console.log("server is live at port 3000");
});