Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
const shutdownServer = async () => {
// Something bad happened, trigger a manual shutdown of lightship,
// which in turn will close the other servers (`registerShutdownHandler`).
// If lightship was not setup due to early error we themeexit the process.
if (lightshipServer) await lightshipServer.shutdown();
else process.exit(1);
};
/**
* 👇 Middlewares
*/
// Gather and expose metrics to Prometheus
const prometheusMetricsMiddleware = createPrometheusMetricsMiddleware({
options: {
accuracies: ['ms'],
metricTypes: ['httpRequestsHistogram'],
metricNames: {
httpRequestDurationInMilliseconds: [
'mc_http_request_duration_milliseconds',
],
},
getLabelValues: () => ({
/**
* NOTE:
* We do not need to know the path. It is only the index.html
* for this service. As it is public facing attackers can "scrape"
* any url causing an unindented increase of cardinality in Prometheus.
*/
path: '',
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({
require('dotenv').config()
const express = require('express')
const { createMiddleware, signalIsUp } = require('@promster/express');
const { createServer } = require('@promster/server');
const subdomain = require('express-subdomain')
const app = express()
const apmRouter = require('./lib/apm-router')
const networks = JSON.parse(process.env.APMSERVE_NETWORKS)
const aliases = JSON.parse(process.env.APMSERVE_ALIASES || '[]')
// Instrument with prometheus metrics
app.use(createMiddleware({ app }));
app.use(require('helmet')())
app.use(require('cors')())
app.use(require('compression')())
// Always check hostname
app.use((req, res, next) => {
req._basehost = process.env.APMSERVE_HOST
if (req.hostname.indexOf(req._basehost) === -1) {
const { target } = aliases.find(({ alias }) => req.hostname === alias) || {}
if (target) {
req.headers.host = `${target}.${req._basehost}`
} else {
return next(new Error('Incorrect HOST name, please set HOST env variable correctly'))
}
}