Change decoding format for single page routes.

This commit is contained in:
Dillon Kearns 2021-04-16 11:33:53 -07:00
parent 9a089b3957
commit 3c14865d2b
2 changed files with 34 additions and 15 deletions

View File

@ -54,7 +54,11 @@ function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
secrets: process.env,
mode,
staticHttpCache: global.staticHttpCache,
request: modifiedRequest,
request: {
payload: modifiedRequest,
kind: "single-page",
jsonOnly: isJson,
},
},
});

View File

@ -38,20 +38,7 @@ decoder :
-> Decode.Decoder (RenderRequest route)
decoder config =
optionalField "request"
(Decode.field "path"
(Decode.string
|> Decode.map
(\path ->
let
route =
pathToUrl path |> config.urlToRoute
in
{ frontmatter = route
, path = config.routeToPath route |> PagePath.build
}
)
)
)
(requestPayloadDecoder config)
|> Decode.map
(\maybeRequest ->
case maybeRequest of
@ -63,6 +50,34 @@ decoder config =
)
{-
payload: modifiedRequest,
kind: "single-page",
jsonOnly: isJson,
-}
requestPayloadDecoder :
ProgramConfig userMsg userModel route siteStaticData pageStaticData sharedStaticData
-> Decode.Decoder (RequestPayload route)
requestPayloadDecoder config =
(Decode.string
|> Decode.map
(\path ->
let
route =
pathToUrl path |> config.urlToRoute
in
{ frontmatter = route
, path = config.routeToPath route |> PagePath.build
}
)
)
|> Decode.field "path"
|> Decode.field "payload"
pathToUrl : String -> Url
pathToUrl path =
{ protocol = Url.Https