forked from NangoHQ/nango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
109 lines (83 loc) · 2.11 KB
/
index.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import express from 'express'
import Bearer from '@bearer/node-agent'
import * as routes from './routes'
export const BUID = 'bearerUid' // TODO - What is this for?
export const PORT = process.env.PORT || 8080
const app = express()
app.set('view engine', 'ejs')
app.set('views', './views')
app.set('trust proxy', 1)
app.use('/assets', express.static('./views/assets'))
/**
* Request log
*/
app.use((req, _res, next) => {
console.log(req.method, req.path)
next()
})
/**
* Project homepage
*/
app.get('/', routes.home)
/**
* API endpoints
*/
app.use('/api', routes.api)
/**
* Authentication endpoints
*/
app.use('/auth', routes.auth)
/**
* Dashboard
*/
app.use('/dashboard', routes.dashboard)
/**
* Proxy feature
*/
app.use('/proxy', routes.proxy)
/**
* Legacy endpoints
*
* Pizzly is a fork of a previous codebase made by Bearer.sh engineering team.
* To help the migration of Bearer's users, we keep here some legacy endpoints.
* It's very likely that these endpoints will be removed by the end of 2020,
* so please do not rely on these endpoints anymore.
*/
app.use('/v2/auth', routes.legacy.auth)
app.use('/apis', routes.legacy.apis)
app.use('/api/v4/functions', routes.legacy.proxy)
/**
* Error handling
*/
app.use((_req, res, _next) => {
res.status(404).render('errors/404')
})
app.use((err, _req, res, _next) => {
console.error(err)
const status = err.status && Number(err.status)
if (status && status >= 400 && status < 500) {
res.status(status).render('errors/' + err.status)
} else {
res.status(500).render('errors/500')
}
})
/**
* Starting up the server
*/
app.listen(PORT, () => {
console.log('Pizzly listening on port', PORT)
if (PORT === 8080) {
console.log('http://localhost:8080')
}
})
/**
* Optional. Initialize the Bearer agent if the environment key is provided.
* Bearer will monitor and shield the Pizzly instance from APIs failure.
* Learn more: https://www.bearer.sh/
*
* To get your BEARER_SECRET_KEY, create an account on www.bearer.sh
* then heads to https://app.bearer.sh/settings/key
*/
if (process.env.BEARER_SECRET_KEY) {
Bearer.init()
}