-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (31 loc) · 1.1 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
const express = require('express');
const path = require('path');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const methodOverride = require('method-override');
const mainRouter = require('./routes/index')
// Express
const app = express();
//Servidor escuchando en el puerto 3000 && Compatibilidad para Heroku
app.listen(process.env.PORT || 3000, function() {
console.log('Servidor corriendo en el puerto 3000');
console.log('http://localhost:3000')
});
//Middlewares: Disponibilidad de la carpeta public y vista 404
app.use(express.static(path.resolve(__dirname, 'public')));
//Procesamiento de formularios
app.use(express.urlencoded( {extended: false} ));
app.use(methodOverride('_method'));
app.use(express.json());
//Gestion de session && almacenamiento cookies
app.use(cookieParser());
// Motor de vistas
app.set("view engine", "ejs");
//Enrutador principal (http://localhost:3000/)
app.use(mainRouter);
//404
app.use((req, res, next) => {
res.status(404).render('error', { message: 'Page not found' });
});
// Exportar app
module.exports = app;