-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (51 loc) · 1.88 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
import 'express-async-errors'
import express from 'express'
import cors from 'cors'
import dotenv from 'dotenv'
import auth from '@moreillon/express_identification_middleware'
import oidcAuth from '@moreillon/express-oidc'
import group_auth from '@moreillon/express_group_based_authorization_middleware'
import root_router from './routes/root'
import measurements_router from './routes/measurements'
import swaggerUi from 'swagger-ui-express'
import swaggerDocument from './swagger-output.json'
import promBundle from 'express-prom-bundle'
import { version } from './package.json'
dotenv.config()
console.log(`Time series storage service v${version}`)
const {
APP_PORT = 80,
IDENTIFICATION_URL,
AUTHORIZED_GROUPS,
GROUP_AUTHORIZATION_URL,
OIDC_JWKS_URI,
} = process.env
const promOptions = { includeMethod: true, includePath: true }
const app = express()
app.use(express.json({ limit: '50mb' }))
app.use(express.text({ type: 'text/*', limit: '50mb' }))
app.use(cors())
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.use(promBundle(promOptions))
app.use('/', root_router)
if (OIDC_JWKS_URI) {
console.log(`[Auth] Enabling OIDC authentication with URI ${OIDC_JWKS_URI}`)
app.use(oidcAuth({ jwksUri: OIDC_JWKS_URI }))
} else if (IDENTIFICATION_URL) {
console.log(`[Auth] Enabling authentication with URL ${IDENTIFICATION_URL}`)
app.use(auth({ url: IDENTIFICATION_URL }))
}
if (AUTHORIZED_GROUPS && GROUP_AUTHORIZATION_URL) {
console.log(`[Auth] Enabling group-based authorization`)
const group_auth_options = {
url: GROUP_AUTHORIZATION_URL,
groups: AUTHORIZED_GROUPS.split(','),
}
app.use(group_auth(group_auth_options))
}
app.use('/measurements', measurements_router)
app.listen(APP_PORT, () => {
console.log(`[Express] listening on port ${APP_PORT}`)
})
// Export for testing
export default app