Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Error handler
app.use(function (err, req, res, next) {
console.error('Error', err)
res.status(503).send({ error: err.message })
})
const port = process.env.PORT || 3000
app.listen(port, (err) => {
if (err) return console.error(err)
signalIsUp()
console.log(`Listening on port ${port} (host: ${process.env.APMSERVE_HOST})`)
})
const metricsPort = process.env.METRICS_PORT || 3001
createServer({ port: metricsPort }).then(server =>
console.log(`@promster/server started on port ${metricsPort}.`)
);
getApps(apiServer).then((apps) => {
const server = express()
server.use(createPrometheusMiddleware({ app: server }))
// Create `/metrics` endpoint on separate server
if (!dev) {
createServer({ port: 9153 }).then(() => console.log(`@promster/server started on port 9153.`))
}
if (!dev) {
server.use(secure);
server.use(morgan('combined'));
}
server.use(cookiesMiddleware());
server.use(compression());
if (process.env.AUTH_PASSWORD) {
server.use(
basicAuth({
users: { admin: process.env.AUTH_PASSWORD },
challenge: true
})
);