-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
61 lines (45 loc) · 1.38 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
var express = require('express');
var app = express(),
config = require('./config'),
mongoose = require('mongoose'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
cookieParser = require('cookie-parser');
mongoose.connect(config.database, function (err) {
if (err) {
console.log("error connecting")
console.log(err);
} else {
//CREATE DATABASE IF NOT EXISTS summonapi;
console.log('Connected to the database');
}
});
// app.set('superSecret', config.secret);
// require('./app/routes')(app);
// config.path = __dirname;
// app.set(config.path);
app.use(cookieParser());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json()); // parse application/json
// app.use(bodyParser.json({ type: 'json/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(bodyParser.json());
app.use(morgan('dev'));
var api = require('./app/routes')(app, express);
app.use('/api', api);
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public/views');
app.use('/js', express.static(__dirname + '/public'));
app.get('*', function (req, res) {
// console.log(req.originalUrl);
res.redirect('/');
});
app.listen(config.port, function (err) {
if (err) {
console.log(err);
} else {
console.log("Magic happens @ http://localhost:%s", config.port);
}
});
// exports = module.exports = app;