-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (42 loc) · 1.51 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
var express = require('express');
var app = express();
var path = require('path');
var port = process.env.PORT || 8080;
var morgan = require('morgan');
var http = require('http');
var bodyParser = require('body-parser');
var index = require('./modules/login');
var campuslist = require('./modules/campuslist');
var usercampus = require('./modules/usercampus');
var mongoose = require('mongoose');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
/*
app.get('/', function(req,res)
{
res.sendFile(path.join(__dirname + '/index.html'));
});*/
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/alliswell');
/*var user1 = new usercampus({ name: 'anupam' }); user1.save();*/
app.use(function(req, res, next) //CORs request handle, coss origin resourse sharing
{
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested=With, content-type, \ Authorisation');
next();
});
app.use(morgan('dev'));
app.set('view engine', 'ejs');
console.log(__dirname);
app.post('/login', index.checks);
/*app.use('/campuslist',campuslist.validtoken);*/
app.get('/', function(req, res, next){
res.render(__dirname + '/view/angular.ejs')
});
app.post('/campuslist', campuslist.validtoken/*usercampus.getcampuslist*/);
/*app.get('/login', function(req,res,next){
res.render(__dirname + '/view/campuslist.ejs')
});*/
app.listen(port);
console.log('let see this port works or not');