fix: crash on missing content type

This commit is contained in:
cha0s 2023-12-04 04:28:11 -06:00
parent dee3330f07
commit 3e073d2660

View File

@ -50,7 +50,7 @@ export const createHttpServer = async (flecks) => {
proxy.on('proxyRes', async (proxyRes, req, res) => {
res.statusCode = proxyRes.statusCode;
// HTML.
if (proxyRes.headers['content-type'].match('text/html')) {
if (proxyRes.headers['content-type']?.match('text/html')) {
// Tests bypass middleware and stream processing.
const {pathname} = new URL(req.url, 'https://example.org/');
if ('/tests.html' === pathname) {
@ -73,7 +73,9 @@ export const createHttpServer = async (flecks) => {
}
// Any other assets.
else {
res.setHeader('Content-Type', proxyRes.headers['content-type']);
if (proxyRes.headers['content-type']) {
res.setHeader('Content-Type', proxyRes.headers['content-type']);
}
proxyRes.pipe(res);
}
});