-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (53 loc) · 1.28 KB
/
server.js
File metadata and controls
67 lines (53 loc) · 1.28 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import express from 'express';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import cors from 'cors';
import sgMail from '@sendgrid/mail';
import { fileURLToPath } from 'url';
import path from 'path';
import {
eventRouter,
userRouter,
slideRouter,
saleRouter,
ticketRouter,
} from './api/routes/index.js';
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
// config environments
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({
path: path.resolve(__dirname, `${process.env.NODE_ENV}.env`),
});
/**
* Mongoose
*/
// Connect to db
const dbConnection = process.env.DB_STRING_CONNECTION;
mongoose.connect(dbConnection);
// Listener to connection error
mongoose.connection.on('error', (e) => {
console.error('ERROR: ', e);
});
/**
* Express
*/
const app = express();
// Middlewares
app.use(cors());
app.use(express.json());
// rutas
app.get('/', (req, res) => {
res.send('API EVENTOPS');
});
app.use('/api', eventRouter);
app.use('/api', userRouter);
app.use('/api', slideRouter);
app.use('/api', saleRouter);
app.use('/api', ticketRouter);
// configurar el puerto donde se escuchara
const PORT = process.env.PORT;
// lanzar servidor
app.listen(PORT, () => {
console.log('- Initialized server -');
});