-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (42 loc) · 1.39 KB
/
app.js
File metadata and controls
52 lines (42 loc) · 1.39 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
const express = require('express');
const path = require('path');
const logger = require('morgan');
const session = require(`express-session`);
//DB
const sequelize = require('./util/database');
//swagger UI
const swaggerUi = require('swagger-ui-express')
const swaggerFile = require('./swagger_output.json')
//locals
const indexRouter = require('./routes/index');
require('./models/Relations')
const app = express();
const port = process.env.PORT || '3000';
app.set('port', port);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'tu_secreto', // Debe ser una cadena aleatoria y segura
resave: false,
saveUninitialized: true,
cookie: { secure: false }, // Configura esto en true para HTTPS
}));
app.use('/', indexRouter);
app.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerFile))
async function databaseActivation(){
try {
await sequelize.sync({alter: true});
app.listen(app.get('port'))
console.log('server litening')
console.log('Connection has been established successfully.');
} catch(error) {
console.error('Unable to connect to the database:', error);
}
}
databaseActivation();
module.exports = app;