-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (37 loc) · 1.48 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const dotenv = require('dotenv');
const { connect } = require('./src/utils/db');
const cors = require('cors');
const userRouter = require('./src/api/routes/user.routes');
const companyRouter = require('./src/api/routes/company.routes');
const messageRouter = require('./src/api/routes/message.routes');
const offerRouter = require('./src/api/routes/offer.routes');
dotenv.config();
const PORT = process.env.PORT || 8000;
const app = express();
connect();
app.get("/", (req, res) => {
res.send("Meettalent Backend Server");
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Method', 'POST, GET, DELETE, PUT, PATCH');
res.header('Access-Control-Allow-Credentials', 'false');
res.header('Access-Control-Allow-Headers', 'Content-Type, Origin, Accept');
res.header('Access-Control-Allow-Origin', '*');
next();
})
app.use(cors({
origin: ['http://localhost:3000', 'https://meettalent.vercel.app/'],
credentials: 'false'
}))
app.use(express.json({limit: '5mb'}));
app.use(express.urlencoded({ extended: false }));
app.use('/user', userRouter);
app.use('/company', companyRouter);
app.use('/message', messageRouter);
app.use('/offer', offerRouter);
app.use('*', (req, res) => res.status(404).json('La ruta seleccionada no existe.'));
app.use((error, res) => {
return res.status( error.status || 500 ).json("Error: " + error.message || "Unexpected error");
})
app.listen(PORT, () => console.log(`listening on port 3030`));