-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (27 loc) · 858 Bytes
/
index.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
const express = require('express');
const { dbConnection } = require('./database/config');
require('dotenv').config();
const cors = require('cors');
// Crear el servidor de express
const app = express();
// Database
dbConnection();
// CORS
app.options('*', cors({origin: 'http://localhost:5173', optionsSuccessStatus: 200}))
app.use(cors(
{ origin: 'http://localhost:5173', optionsSuccessStatus: 200}
));
// Directorio publico
app.use( express.static('public'));
//Lectura y parseo del body
app.use(express.json());
//Rutas
app.use( '/api/auth', require('./routes/auth'));
app.use( '/api/events', require('./routes/events'));
app.get('*', (req, res) => {
res.sendFile( __dirname + '/public/index.html');
});
//Escuchar peticiones
app.listen( process.env.PORT, () => {
console.log(`servidor corriendo en puerto ${ process.env.PORT }`);
})