-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (58 loc) · 1.87 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
62
63
64
65
66
67
68
69
70
71
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var io = require('./server/routes/socket').listen(server);
var cookieParser = require('cookie-parser');
var session = require('express-session');
var morgan = require('morgan');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var passport = require('passport');
var flash = require('connect-flash');
var path = require('path');
var api = express.Router();
var port = process.env.PORT||4000;
var configDB = require('./server/config/database');
mongoose.connect(configDB.url, function(err, res) {
mongoose.Promise = global.Promise;
if(err){
console.info('Nao foi possivel conectar a:' + configDB.url + ' com o erro: ' + err);
}else{
console.info('Conectado a ' + configDB.url);
}
});
require('./server/config/passport')(passport);
app.use(morgan('dev'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(session({secret: 'anystringoftext', saveUninitialized: true, resave: true}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.set('view engine', 'ejs');
app.set('views', path.resolve(__dirname, 'public', 'site'));
app.use(express.static(path.resolve(__dirname, 'public')));
// App
require('./server/routes/app')(api);
app.use('/', api);
// API
require('./server/routes/api')(api, passport);
app.use('/api', api);
// Tratamentos de exceção
// ==============================
// Erro 404
app.use(function(req, res) {
res.render('./pages-status/404.ejs');
});
// Erro 500
app.use(function(error, req, res, next) {
res.render('./pages-status/500.ejs', {error: error});
});
/*
Run
*/
server.listen(port, function(){
console.info('Rodando em ' + port);
});