-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (42 loc) · 1.2 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
48
49
50
// Import Node Libraries
const { auth, requiresAuth } = require('express-openid-connect');
const express = require('express');
const bodyParser = require('body-parser');
// Import Own Libraries
const mongodb = require('./db/connect');
// Changing the port to listen to
const port = process.env.PORT || 8090;
// Instance of express API
const myApp = express();
// For OAuth 2.0
const dotenv = require('dotenv')
dotenv.config();
const config = {
authRequired: false,
auth0Logout: true,
secret: process.env.SECRET,
baseURL: process.env.BASE_URL,
clientID: process.env.CLIENT_ID,
issuerBaseURL: process.env.ISSUER_BASE_URL
};
myApp.use(bodyParser.json())
.use((req, res, next) => {
// Preparing headings
res.setHeader('Access-Control-Allow-Origin', '*');
next();
})
.use(auth(config))
// Redirect to routes
.use('/', requiresAuth(), require('./routes')
);
// Staring database access service
mongodb.initDb((err, mongodb) => {
if (err) {
// *** Handling Errors *** //
console.log(err);
} else {
// Starting app service and listening to on 8080
myApp.listen(port);
console.log(`Connected to DB and listening on ${port}`);
}
})