-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (41 loc) · 1.08 KB
/
app.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
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { gradeRouter } from './routes/gradeRouter.js';
import { db } from './models/index.js';
import gradeModel from './models/gradeModel.js';
(async () => {
try {
await db.mongoose.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
} catch (error) {
process.exit();
}
})();
const app = express();
//define o dominio de origem para consumo do servico
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
let whitelist = [
'https://desafio4-grade-app.herokuapp.com/',
'http://localhost:3000',
];
let corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
};
app.use(cors(corsOptions));
// app.use('/grade');
app.use('/', gradeRouter);
// app.get('/', (req, res) => {
// res.send('API em execucao');
// });
// console.log('object');
app.listen(process.env.PORT || 8081, () => {});