-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (47 loc) · 1.37 KB
/
index.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
51
52
53
54
55
56
57
// import dependencies
const express = require('express');
const path = require('path');
require("dotenv").config();
const mongoose = require('mongoose');
const session = require('express-session');
const { auth, requiresAuth } = require('express-openid-connect');
const port = process.env.PORT || 3000
const app = express();
// paths, ejs, and url setup
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.urlencoded({extended:false}));
app.use(express.json());
// oauth
const config = {
issuerBaseURL: process.env.AUTH0_ISSUER_BASE_URL,
baseURL: process.env.BASE_URL,
clientID: process.env.AUTH0_CLIENT_ID,
secret: process.env.SECRET,
authRequired: false,
auth0Logout: true,
};
app.use(auth(config));
// database connection
const url = process.env.CONNECTIONSTRING;
mongoose.connect(url, {useNewUrlParser:true})
const con = mongoose.connection
// session
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: true
}));
//routers
const strainRouter = require('./routes/strain');
// routes
app.use('/', strainRouter);
// oauth
app.get('/profile', requiresAuth(), (req, res) => {
res.send(JSON.stringify(req.oidc.user, null, 2));
});
// server
app.listen(port,() => {
console.log('Server running at http://localhost:8080');
});