-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (28 loc) · 916 Bytes
/
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
// Import dependencies
const express = require('express');
const MongoClient = require('mongodb');
// Import routes
const defineRoutes = require('./routes');
// Initialize the app
const app = express();
// Set database credentials
const MONGODB_URI = process.env.MONGODB_URI;
const MONGODB_NAME = process.env.MONGODB_NAME;
MongoClient.connect(MONGODB_URI)
.then(client => {
console.log('Connected to MongoDB');
const db = client.db(MONGODB_NAME);
const collection = db.collection('drops');
// Enable CORS
// (See https://enable-cors.org/server_expressjs.html)
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
defineRoutes(app, collection);
})
.catch(error => {
console.log(error);
});
module.exports = app;