-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (55 loc) · 1.9 KB
/
app.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
#!/usr/bin/env
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var MemoryStore = require('session-memory-store')(session);
var models = require('./app/models/');
var app = express();
var port = process.env.PORT || 8080;
var env = process.env.NODE_ENV || 'development';
var passport = require('passport');
var flash = require('connect-flash');
app.use(morgan('dev')); // log
app.use(cookieParser()); // cookies
app.use(bodyParser.urlencoded({
limit: '50mb',
extended: true
}));
app.use(bodyParser.json({limit: '50mb'}));
app.use(express.static('public'));
app.use(express.static('node_modules'));
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
app.set('view engine', 'ejs');
// passport
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
store: new MemoryStore(),
} )); // secret
require('./app/config/passport')(passport, env);
app.use(passport.initialize());
app.use(passport.session()); // sessions
app.use(flash());
app.use(function(req, res, next){
res.locals.message = req.flash('message')[0];
res.locals.success = req.flash('success')[0];
console.log(res.locals);
next();
});
// routes ======================================================================
require('./app/routes.js')(app, passport, models, port);
app.use(function(req, res, next){
res.status(404);
res.redirect("/")
});
// launch ======================================================================
app.listen(port);
console.log('La magia pasa en el puerto ' + port);