fix: tests.html bypasses middleware and stream processing
This commit is contained in:
parent
e13b91a57b
commit
04d7094cea
|
@ -53,6 +53,15 @@ export const createHttpServer = async (flecks) => {
|
||||||
res.statusCode = proxyRes.statusCode;
|
res.statusCode = proxyRes.statusCode;
|
||||||
// HTML.
|
// 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) {
|
||||||
|
if (!res.headersSent) {
|
||||||
|
res.setHeader('Content-Type', proxyRes.headers['content-type']);
|
||||||
|
}
|
||||||
|
proxyRes.pipe(res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
routeMiddleware(req, res, (error) => {
|
routeMiddleware(req, res, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
res.status(error.code || 500).end(error.stack);
|
res.status(error.code || 500).end(error.stack);
|
||||||
|
@ -82,6 +91,12 @@ export const createHttpServer = async (flecks) => {
|
||||||
else {
|
else {
|
||||||
// Serve the document root, sans index.
|
// Serve the document root, sans index.
|
||||||
app.use(express.static(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT), {index: false}));
|
app.use(express.static(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT), {index: false}));
|
||||||
|
// Tests bypass middleware and stream processing.
|
||||||
|
app.get('/tests.html', (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
const stream = createReadStream(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT, 'tests.html'));
|
||||||
|
stream.pipe(res);
|
||||||
|
});
|
||||||
// Fallback to serving HTML.
|
// Fallback to serving HTML.
|
||||||
app.get('*', routeMiddleware, async (req, res) => {
|
app.get('*', routeMiddleware, async (req, res) => {
|
||||||
if (req.accepts('text/html')) {
|
if (req.accepts('text/html')) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user