-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 1013 Bytes
/
server.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
require('dotenv').config()
console.log('PORT:', process.env.PORT)
const express = require('express')
const app = express()
const { auth } = require('express-openid-connect')
const config = {
authRequired: false,
auth0Logout: true,
secret: process.env.SECRET,
baseURL: process.env.BASEURL,
clientID: process.env.CLIENTID,
issuerBaseURL: process.env.ISSUER
};
// middleware - middle man between getting a request (e.g. GET request) and sending data
app.use((req, res, next) => {
console.log(req.path, req.method)
next()
})
app.use(auth(config))
// route handling
app.get('/', (req, res) => {
res.json({mssg: "What's up"})
console.log(req.oidc.isAuthenticated())
})
app.get('/', (req, res) => {
console.log(req.oidc.isAuthenticated())
res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out')
res.render("server", {title : "express demo"})
})
app.listen(process.env.PORT, () => {
console.log(`Server running on port ${process.env.PORT}.`)
})