* expose fetchLimitBytes/userAgent in got-config module * export a function not a factory * send better user-agent values - add userAgentBase setting - send short SHA in user agent on heroku - set a version (tag or short SHA) in Dockefile and use it to report server version in UA for docker users * add a comment explaining fileSize Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
27 lines
803 B
JavaScript
27 lines
803 B
JavaScript
import bytes from 'bytes'
|
|
import configModule from 'config'
|
|
import Joi from 'joi'
|
|
import { fileSize } from '../../services/validators.js'
|
|
|
|
const schema = Joi.object({
|
|
fetchLimit: fileSize,
|
|
userAgentBase: Joi.string().required(),
|
|
}).required()
|
|
const config = configModule.util.toObject()
|
|
const publicConfig = Joi.attempt(config.public, schema, { allowUnknown: true })
|
|
|
|
const fetchLimitBytes = bytes(publicConfig.fetchLimit)
|
|
|
|
function getUserAgent(userAgentBase = publicConfig.userAgentBase) {
|
|
let version = 'dev'
|
|
if (process.env.DOCKER_SHIELDS_VERSION) {
|
|
version = process.env.DOCKER_SHIELDS_VERSION
|
|
}
|
|
if (process.env.HEROKU_SLUG_COMMIT) {
|
|
version = process.env.HEROKU_SLUG_COMMIT.substring(0, 7)
|
|
}
|
|
return `${userAgentBase}/${version}`
|
|
}
|
|
|
|
export { fetchLimitBytes, getUserAgent }
|