1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/middleware/early-access-proxy.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

26 lines
746 B
JavaScript

// This module serves requests to Early Access content from a hidden proxy host (EARLY_ACCESS_HOSTNAME).
// Paths to this content are fetched in the warmServer module at startup.
const got = require('got')
const isURL = require('is-url')
module.exports = async (req, res, next) => {
if (
isURL(process.env.EARLY_ACCESS_HOSTNAME) &&
req.context &&
req.context.earlyAccessPaths &&
req.context.earlyAccessPaths.includes(req.path)
) {
try {
const proxyURL = `${process.env.EARLY_ACCESS_HOSTNAME}${req.path}`
const proxiedRes = await got(proxyURL)
res.set('content-type', proxiedRes.headers['content-type'])
res.send(proxiedRes.body)
} catch (err) {
next()
}
} else {
next()
}
}