-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (56 loc) · 1.66 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict'
require('./config')
const http = require('http')
const express = require('express')
const morgan = require('morgan')
const middleware = require('./middleware')
const zoomAppRouter = require('./api/zoomapp/router')
const zoomRouter = require('./api/zoom/router')
const thirdPartyOAuthRouter = require('./api/thirdpartyauth/router')
require('dotenv').config()
// Create app
const app = express()
// Set view engine (for system browser error pages)
app.set('view engine', 'pug')
// Set static file directory (for system browser error pages)
app.use('/', express.static('public'))
// Set universal middleware
app.use(morgan('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(middleware.session)
app.use(middleware.setResponseHeaders)
// Zoom App routes
app.use('/api/zoomapp', zoomAppRouter)
if (
process.env.AUTH0_CLIENT_ID &&
process.env.AUTH0_CLIENT_SECRET &&
process.env.AUTH0_ISSUER_BASE_URL
) {
app.use('/api/auth0', thirdPartyOAuthRouter)
} else {
// console.log('Please add Auth0 env variables to enable the /auth0 route')
}
app.use('/zoom', zoomRouter)
app.get('/hello', (req, res) => {
res.send('Hello Zoom Apps!')
})
// Handle 404
app.use((req, res, next) => {
const error = new Error(`404 Not found: ${req.originalUrl}`)
error.status = 404
next(error)
})
// Handle errors (system browser only)
app.use((error, req, res) => {
res.status(error.status || 500)
res.render('error', {
title: 'Error',
message: error.message,
stack: error.stack,
})
})
// Start express server
http.createServer(app).listen(process.env.PORT, () => {
console.log('Zoom App is listening on port', process.env.PORT)
})