-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (26 loc) · 1.01 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
var express = require('express');
var cors = require('cors');
const createTodosRepository = require("./repositories/todos.repository");
const createApplication = (db, configuration) => {
const router = express.Router();
const repository = createTodosRepository({mongoDatabase: db});
require("./routes/todos.router")(router, repository);
const app = express();
app.use(cors({
origin: '*',
allowedHeaders: ["Content-Type", "Authorization"],
exposedHeaders: "Location"
}));
app.options('*', cors())
app.all('', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
app.use(express.json());
app.use('/', router);
app.set('port', configuration.port);
return app;
}
module.exports = createApplication;