-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
34 lines (24 loc) · 1.14 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
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const app = express();
const userRoutes = require("./src/api/routes/users.routes");
//MongoDB connection PATH
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true
});
mongoose.Promise = global.Promise;//Supresses a warning about promises.
mongoose.set('useCreateIndex', true); //Suppresses the warning about collection.ensureIndex
mongoose.set('useCreateIndex', true); //Suppresses the warning about collection.ensureIndex
app.use("/imageUploads", express.static('imageUploads'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
//Before any request is done we have to "disable" CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*') //second parameter specifies the url that can have access, no url means all can access.
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH');
next();
});
app.use("/users/", userRoutes);
module.exports = app;