Files
shields/lib/server-config.js
Paul Melnikow 51897b3c7e Precompute text width using a lookup table (#2311)
This simplifies and further optimizes text-width computation by computing the entire width table in advance, and serializing it in the style of QuickTextMeasurer (#1390). This entirely removes the need for PDFKit at runtime. This has the advantage of fixing #1305 – more generally: producing the same result everywhere – without having to deploy a copy of Verdana.

The lifting is delegated to these three libraries, which are housed in a monorepo: https://github.com/metabolize/anafanafo

I'd be happy to move it into the badges org if folks want to collaborate on maintaining them.

QuickTextMeasurer took kerning pairs into account, whereas this implementation does not. I was thinking kerning would be a necessary refinement, though this seems to work well enough.

I dropped in a binary-search package to traverse the data structure, in part to conserve space. This causes a moderate performance regression, though there is ample room for improving on that: https://github.com/badges/shields/pull/2311#issuecomment-439182704
2018-11-15 17:27:21 -05:00

79 lines
2.0 KiB
JavaScript

'use strict'
// This file should only be required by server.js. To simplify testing, config
// should be injected into other components needing it.
const url = require('url')
const envFlag = require('node-env-flag')
function envArray(envVar, defaultValue, delimiter) {
delimiter = delimiter || ','
if (envVar) {
return envVar.split(delimiter)
} else {
return defaultValue
}
}
const isSecure = envFlag(process.env.HTTPS, false)
const port = +process.env.PORT || +process.argv[2] || (isSecure ? 443 : 80)
const address = process.env.BIND_ADDRESS || process.argv[3] || '::'
const baseUri = url.format({
protocol: isSecure ? 'https' : 'http',
hostname: address,
port,
pathname: '/',
})
// The base URI provides a suitable value for development. Production should
// configure this.
const allowedOrigin = envArray(
process.env.ALLOWED_ORIGIN,
baseUri.replace(/\/$/, ''),
','
)
const config = {
bind: {
port,
address,
},
metrics: {
prometheus: {
enabled: envFlag(process.env.METRICS_PROMETHEUS_ENABLED, false),
allowedIps: process.env.METRICS_PROMETHEUS_ALLOWED_IPS,
},
},
ssl: {
isSecure,
key: process.env.HTTPS_KEY,
cert: process.env.HTTPS_CRT,
},
baseUri,
redirectUri: process.env.REDIRECT_URI || process.env.INFOSITE,
cors: {
allowedOrigin,
},
persistence: {
dir: process.env.PERSISTENCE_DIR || './private',
redisUrl: process.env.REDIS_URL || process.env.REDISTOGO_URL,
},
services: {
github: {
baseUri: process.env.GITHUB_URL || 'https://api.github.com',
debug: {
enabled: envFlag(process.env.GITHUB_DEBUG_ENABLED, false),
intervalSeconds: process.env.GITHUB_DEBUG_INTERVAL_SECONDS || 300,
},
},
trace: envFlag(process.env.TRACE_SERVICES),
},
profiling: {
makeBadge: envFlag(process.env.PROFILE_MAKE_BADGE),
},
rateLimit: envFlag(process.env.RATE_LIMIT, true),
handleInternalErrors: envFlag(process.env.HANDLE_INTERNAL_ERRORS, true),
}
module.exports = config