-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (39 loc) · 1.63 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
/* Entrega final E-commerce*/
console.log(' ')
console.log('----------------------------------')
console.log(' Proyecto final - Backend')
console.log(' E-commerce: by Cecilia Perdomo')
console.log('----------------------------------')
console.log(' ')
const express = require('express')
const cors = require('cors')
require('dotenv').config()
/* Routes */
const productoRoutes = require('./src/routes/productoRoutes')
const carritoRoutes = require('./src/routes/carritoRoutes')
const authRoutes = require('./src/routes/authRoutes')
const config = require('./config/config')
const app = express()
if(config.NODE_ENV == 'development') app.use(cors())
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/* ----------------------------------------------------------- */
/* MANEJO DE RUTAS */
/* ----------------------------------------------------------- */
/* Productos */
const productoRouter = new productoRoutes()
app.use('/productos', productoRouter.start())
/* Carritos */
const carritoRouter = new carritoRoutes()
app.use('/carrito', carritoRouter.start())
/* Autenticacion de usuarios */
const authRouter = new authRoutes()
app.use('/login', authRouter.start())
/* ----------------------------------------------------------- */
/* SERVER LISTEN */
/* ----------------------------------------------------------- */
const PORT = config.PORT || 8080
const srv = app.listen(PORT, () => {
console.log(`Escuchando en el puerto: ${PORT} (${config.NODE_ENV})`)
})
srv.on('error', error => console.log(`Error en el servidor ${error}`))