-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (46 loc) · 1.47 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
require('dotenv').load();
var express = require('express'),
jwt = require('jsonwebtoken');
morgan = require('morgan'),
bodyParser = require('body-parser'),
mongoose = require('mongoose'),
User = require('./server/models/user.server.model'),
cors = require('cors'),
secrets = require('./config/secrets'),
testdb = require('./config/testdb'),
route = require('./server/routes');
var port = process.env.PORT || 3000;
/**
* Connect to MongoDB.
*/
testdb.dbconnect();
/**
* Create Express server.
*/
var app = express();
/**
* Express configuration.
*/
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended: true})); //use bodyParser for request and parsing info
app.use(bodyParser.json());
app.use(express.static( __dirname + '/public')); //use to serve static files like favicon, css, angular and the rest
/**
* Routes Configuration
*/
route(app);
//configure any route whatsoever to redirect to angular
app.get('*', function(req, res) {
/** frontend routes =========================================================
* route to handle all angular requests
* load the single view file (angular will handle the page changes on the front-end)
**/
res.sendFile(__dirname + '/public/index.html' );
});
/**
* Start Express server.
*/
app.listen( port, function(){
console.log("Mean Map Server Listening on port ", port );
});