Retain staticHttp cache in dev server.

This commit is contained in:
Dillon Kearns 2021-04-09 13:22:12 -07:00
parent b23c774b68
commit ebb78e541a
4 changed files with 11 additions and 3 deletions

View File

@ -11,6 +11,8 @@ const kleur = require("kleur");
const serveStatic = require("serve-static");
const connect = require("connect");
global.staticHttpCache = {};
const { inject } = require("elm-hot");
const serve = serveStatic("static/", { index: false });
const serveStaticCode = serveStatic(path.join(__dirname, "../static-code"), {

View File

@ -40,13 +40,12 @@ function runElmApp(compiledElmPath, pagePath, request) {
const route = pagePath.replace(/content\.json\/?$/, "");
const mode = "elm-to-html-beta";
const staticHttpCache = {};
const modifiedRequest = { ...request, path: route };
const app = requireUncached(compiledElmPath).Elm.TemplateModulesBeta.init({
flags: {
secrets: process.env,
mode,
staticHttpCache,
staticHttpCache: global.staticHttpCache,
request: modifiedRequest,
},
});
@ -68,6 +67,7 @@ function runElmApp(compiledElmPath, pagePath, request) {
// generateFiles(fromElm.args[0].filesToGenerate);
} else if (fromElm.tag === "PageProgress") {
const args = fromElm.args[0];
global.staticHttpCache = args.staticHttpCache;
console.timeEnd(`renderer-${pagePath}`);
if (isJson) {

View File

@ -11,6 +11,7 @@ module Pages.Internal.Platform.Cli exposing
import BuildError exposing (BuildError)
import Codec
import Dict exposing (Dict)
import Dict.Extra
import ElmHtml.InternalTypes exposing (decodeElmHtml)
import ElmHtml.ToString exposing (FormatOptions, defaultFormatOptions, nodeToStringWithOptions)
import Head
@ -830,7 +831,7 @@ sendSinglePageProgress :
-> Model pathKey route
-> ( PagePath pathKey, route )
-> Effect pathKey
sendSinglePageProgress toJsPayload config _ _ =
sendSinglePageProgress toJsPayload config _ model =
\( page, _ ) ->
let
makeItWork : StaticHttpRequest.RawRequest staticData -> Result BuildError staticData
@ -900,6 +901,7 @@ sendSinglePageProgress toJsPayload config _ _ =
, head = success.head
, title = viewValue.title
, body = "" --lookedUp.unparsedBody
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\k v -> v)
}
|> sendProgress

View File

@ -33,6 +33,7 @@ type alias ToJsSuccessPayloadNew pathKey =
, head : List (Head.Tag pathKey)
, body : String
, title : String
, staticHttpCache : Dict String String
}
@ -183,6 +184,9 @@ successCodecNew canonicalSiteUrl currentPagePath =
|> Codec.field "head" .head (Codec.list (headCodec canonicalSiteUrl currentPagePath))
|> Codec.field "body" .body Codec.string
|> Codec.field "title" .title Codec.string
|> Codec.field "staticHttpCache"
.staticHttpCache
(Codec.dict Codec.string)
|> Codec.buildObject