Skip to content

Commit

Permalink
Merge pull request #53 from lyft/status-endpoints
Browse files Browse the repository at this point in the history
Status endpoints
  • Loading branch information
schottra authored Apr 1, 2020
2 parents 1c0b68b + 61cb82c commit 292efbb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.git
.env
node_modules
Dockerfile
.dockerignore
npm-debug.log
.storybook
.vscode
14 changes: 13 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const CORS_PROXY_PREFIX = process.env.CORS_PROXY_PREFIX || '/cors_proxy';
const CONFIG_DIR = process.env.CONFIG_DIR || './config';
const CONFIG_CACHE_TTL_SECONDS = process.env.CONFIG_CACHE_TTL_SECONDS || '60';

// Defines a file to be required which will provide implementations for
// any user-definable code.
const PLUGINS_MODULE = process.env.PLUGINS_MODULE;

// Optional URL which will provide information about system status. This is used
// to show informational banners to the user.
// If it has no protocol, it will be treated as relative to window.location.origin
const STATUS_URL = process.env.STATUS_URL;

module.exports = {
ADMIN_API_URL,
BASE_URL,
Expand All @@ -23,10 +32,13 @@ module.exports = {
CONFIG_DIR,
CORS_PROXY_PREFIX,
NODE_ENV,
PLUGINS_MODULE,
STATUS_URL,
processEnv: {
ADMIN_API_URL,
BASE_URL,
CORS_PROXY_PREFIX,
NODE_ENV
NODE_ENV,
STATUS_URL
}
};
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ const fs = require('fs');
const morgan = require('morgan');
const express = require('express');
const env = require('./env');
const { applyMiddleware } = require('./plugins');

const corsProxy = require('./corsProxy.js');

const app = express();

// Enable logging for HTTP access
app.use(morgan('combined'));
app.use(express.json());

app.get(`${env.BASE_URL}/healthz`, (_req, res) => res.status(200).send());
app.use(corsProxy(`${env.BASE_URL}${env.CORS_PROXY_PREFIX}`));

if (typeof applyMiddleware === 'function') {
console.log('Found middleware plugins, applying...');
applyMiddleware(app);
}

if (process.env.NODE_ENV === 'production') {
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
Expand Down
11 changes: 11 additions & 0 deletions plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const env = require('./env');

const { middleware } = env.PLUGINS_MODULE ? require(env.PLUGINS_MODULE) : {};

if (Array.isArray(middleware)) {
module.exports.applyMiddleware = app => middleware.forEach(m => m(app));
} else if (middleware !== undefined) {
console.log(
`Expected middleware to be of type Array, but got ${middleware} instead`
);
}
1 change: 1 addition & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface Env extends NodeJS.ProcessEnv {
BASE_URL?: string;
CORS_PROXY_PREFIX: string;
DISABLE_ANALYTICS?: string;
STATUS_URL?: string;
}

0 comments on commit 292efbb

Please sign in to comment.