-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (42 loc) · 1.41 KB
/
server.js
File metadata and controls
54 lines (42 loc) · 1.41 KB
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
var express = require('express');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.all('/*', function(req, res, next) {
// CORS headers
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,POST');
// Set custom headers for CORS
res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key');
next();
});
// Auth Middleware - This will check if the token is valid
app.all('/api/*', require('./validation/validateToken.js'));
//This handles the login and register
app.use('/', require('./routes'));
app.get('/', function(req, res){
res.sendFile(__dirname + '/pages/main.html');
});
// If no route is matched by now, it must be a 404
app.use(function(req, res, next) {
// var err = new Error('Not Found');
// err.status = 404;
// next(err);
res.status(404);
res.json({
"error":"Page Not Found"
})
});
// Start the server
app.set('port', process.env.PORT || 3005);
// Connect to our databse
var promise = mongoose.connect(require('./config.js').database, {
useMongoClient: true,
})
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + server.address().port);
});