Avoid express.static ETag handling for index template

Fixes "undefined" under the map
pull/108/head
Candid Dauth 2017-02-13 12:39:17 +01:00
rodzic e5fd3eee03
commit 5c501fbc00
2 zmienionych plików z 14 dodań i 7 usunięć

Wyświetl plik

@ -358,7 +358,9 @@ function interceptWriteStream(writeStream) {
};
writeStream.end = function(chunk, encoding, callback) {
response += chunk;
if(chunk) {
response += chunk;
}
writeStream.write = writeBkp;
writeStream.send = sendBkp;

Wyświetl plik

@ -1,6 +1,7 @@
const compression = require("compression");
const ejs = require("ejs");
const express = require("express");
const fs = require("fs");
const http = require("http");
const path = require("path");
const Promise = require("promise");
@ -27,13 +28,17 @@ const webserver = module.exports = {
const padMiddleware = function(req, res, next) {
utils.promiseAuto({
template: () => {
// We have to let staticMiddleware create the page for us first, we cannot read it directly from the
// file system (as webpackMiddleware might have to inject the bundle files into it).
if (process.env.FM_DEV) {
let intercept = utils.interceptWriteStream(res);
req.url = req.originalUrl = "/index.ejs";
staticMiddleware(req, res, next);
return intercept;
} else {
// We don't want express.static's ETag handling, as it sometimes returns an empty template,
// so we have to read it directly from the file system
let intercept = utils.interceptWriteStream(res);
req.url = req.originalUrl = "/index.ejs";
staticMiddleware(req, res, next);
return intercept;
return Promise.denodeify(fs.readFile)(`${frontendPath}/build/index.ejs`, "utf8");
}
},
padData: () => {