forked from OHDSI/WebAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
75 lines (67 loc) · 2.95 KB
/
Copy pathapp.js
File metadata and controls
75 lines (67 loc) · 2.95 KB
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
import express from 'express'
import userMiddleware from './middleware/user.js'
import proxyBaseMiddleware from './middleware/proxyBase.js'
import errorHandler from './middleware/errors.js'
import i18nRouter from './routes/i18n.js'
import infoRouter from './routes/info.js'
import sourceRouter from './routes/source.js'
import userRouter from './routes/user.js'
import vocabularyRouter from './routes/vocabulary.js'
import conceptsetRouter from './routes/conceptset.js'
import cohortdefinitionRouter from './routes/cohortdefinition.js'
import cdmresultsRouter from './routes/cdmresults.js'
import notificationsRouter from './routes/notifications.js'
import jobRouter from './routes/job.js'
import irRouter from './routes/ir.js'
import cohortcharacterizationRouter from './routes/cohortcharacterization.js'
import pathwayRouter from './routes/pathway.js'
import estimationRouter from './routes/estimation.js'
import predictionRouter from './routes/prediction.js'
import tagsRouter from './routes/tags.js'
import cohortresultsRouter from './routes/cohortresults.js'
import personRouter from './routes/person.js'
import sqlrenderRouter from './routes/sqlrender.js'
const app = express()
// strict: false allows bare JSON primitives (Atlas sends a bare timestamp to POST /notifications/viewed)
app.use(express.json({ limit: '10mb', strict: false }))
// Atlas sends cross-origin requests from its own origin
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization,User-Language,Action-Location')
if (req.method === 'OPTIONS') return res.sendStatus(204)
next()
})
app.use(proxyBaseMiddleware)
app.use(userMiddleware)
app.use((req, res, next) => {
const start = Date.now()
res.on('finish', () => {
const ms = Date.now() - start
process.stdout.write(`${new Date().toISOString()} ${req.method} ${req.originalUrl} ${res.statusCode} ${ms}ms\n`)
})
next()
})
app.use('/i18n', i18nRouter)
app.use('/info', infoRouter)
app.use('/source', sourceRouter)
app.use('/vocabulary', vocabularyRouter)
app.use('/conceptset', conceptsetRouter)
app.use('/cohortdefinition', cohortdefinitionRouter)
app.use('/cdmresults', cdmresultsRouter)
app.use('/notifications', notificationsRouter)
app.use('/job', jobRouter)
app.use('/ir', irRouter)
app.use('/cohort-characterization', cohortcharacterizationRouter)
app.use('/pathway-analysis', pathwayRouter)
app.use('/estimation', estimationRouter)
app.use('/prediction', predictionRouter)
app.use('/tag', tagsRouter)
app.use('/cohortresults', cohortresultsRouter)
app.use('/sqlrender', sqlrenderRouter)
// Person profile: /:sourceKey/person/:personId — must come after all fixed-prefix routes
app.use('/:sourceKey/person', personRouter)
app.use('/', userRouter)
app.use((req, res) => res.status(404).json({ message: `Cannot ${req.method} ${req.path}` }))
app.use(errorHandler)
export default app