-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (33 loc) · 1.3 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
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
import dotenv from 'dotenv';
import session from 'express-session';
import sessionConfig from './.config/session.config.js';
import indexRoutes from './routes/index.routes.js'
const app = express();
dotenv.config();
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors(
{
origin: 'https://project-manager-app-russell.netlify.app',
// origin : 'http://localhost:3001',
methods: ['GET', 'POST', 'PUT', 'DELETE'],
credentials: true
}
));
// required for the app when deployed to Heroku (in production)
app.set('trust proxy', 1)
app.use(sessionConfig);
//TODO INVESTIGAR HARDCODEO
app.use('/', indexRoutes);
app.use(function (err, req, res, next) {
console.log("Global Error handler,some thing didnt work:", err.message)
res.status(500).json({ devMesg: "global Error Handler", ErrorMessage: err.message })
})
const PORT = process.env.PORT || 3000;
mongoose.connect(process.env.CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => app.listen(PORT, () => console.log(`Server running on port': ${PORT}`)))
.catch((error) => console.log(error.message));