-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (47 loc) · 1.76 KB
/
app.js
File metadata and controls
56 lines (47 loc) · 1.76 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
import {inspect} from 'node:util'
inspect.defaultOptions.depth = null
import express from 'express'
import path from 'path'
import logger from 'morgan'
import {fileURLToPath} from 'url'
import indexRouter from './routes/index.js'
import providersRouter from './routes/providers.js'
import prometheusRouter from './routes/prometheus.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
import cors from 'cors'
import Debug from 'debug'
const debug = Debug('ipfs-tracker:server')
const logKey = process.argv.includes('--log-key') && process.argv[process.argv.indexOf('--log-key') + 1]
const app = express()
// remove x-powered-by: express
app.use((req, res, next) => {
res.removeHeader('X-Powered-By')
next()
})
// trust x-forwarded-for, the app will almost always use a proxy
app.set('trust proxy', true)
app.use(cors())
if (debug.enabled) {
// app.use(logger('dev'))
app.use(logger(':remote-addr :remote-user :user-agent :method :url :status :response-time ms - :res[content-length]'))
}
app.use(express.json({
limit: '1mb',
// TODO: kubo doesn't always include content-type header, remove after delegated routing spec
type: (req) => req.method === 'POST' || req.method === 'PUT'
}))
// TODO: figure out why did I comment this out?
// app.use(express.urlencoded({ extended: false }))
// app.use(express.static(path.join(__dirname, 'public')))
// metrics
app.use('/metrics/prometheus', prometheusRouter)
// needed for when used in the plebbit provider because it only proxies /routing/v1/providers/
app.use('/routing/v1/providers/metrics/prometheus', prometheusRouter)
// routes
app.use('/', indexRouter)
app.use('/routing/v1/providers/', providersRouter)
// logs
if (logKey) {
app.use('/log', express.static(path.join(__dirname, 'log')))
}
export default app