How to use @promster/express - 7 common examples

To help you get started, we’ve selected a few @promster/express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / merchant-center-application-kit / packages / mc-http-server / server.js View on Github external
});

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: '',
github blockstack / app.co / server.js View on Github external
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({
github aragon / apm-serve / index.js View on Github external
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'))
    }
  }
github commercetools / merchant-center-application-kit / packages / mc-http-server / routes / metrics.spec.js View on Github external
it('should invoke `setHeader` with the `register` content-type', () => {
      expect(response.setHeader).toHaveBeenCalledWith(
        'Content-Type',
        getContentType()
      );
    });
github commercetools / merchant-center-application-kit / packages / mc-http-server / routes / metrics.spec.js View on Github external
it('should invoke `end` on the `response` with the `getSummary` metrics', () => {
      expect(response.end).toHaveBeenCalledWith(getSummary());
    });
  });
github commercetools / merchant-center-application-kit / packages / mc-http-server / routes / metrics.js View on Github external
module.exports = function metrics(request, response) {
  if (
    request.headers &&
    request.headers.via &&
    request.headers.via.includes('google')
  ) {
    response.statusCode = 200;

    response.end();
  } else {
    response.statusCode = 200;

    response.setHeader('Content-Type', getContentType());
    response.end(getSummary());
  }
};
github commercetools / merchant-center-application-kit / packages / mc-http-server / routes / metrics.js View on Github external
module.exports = function metrics(request, response) {
  if (
    request.headers &&
    request.headers.via &&
    request.headers.via.includes('google')
  ) {
    response.statusCode = 200;

    response.end();
  } else {
    response.statusCode = 200;

    response.setHeader('Content-Type', getContentType());
    response.end(getSummary());
  }
};

@promster/express

Express server integrations of promster

MIT
Latest version published 20 days ago

Package Health Score

83 / 100
Full package analysis