Skip to content

Commit

Permalink
Add missing fields to netlify adapter and make request decoder more r…
Browse files Browse the repository at this point in the history
…obust.
  • Loading branch information
dillonkearns committed Jun 1, 2023
1 parent 8e5a50a commit 3774147
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
3 changes: 2 additions & 1 deletion adapter/netlify.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ async function render(event, context) {
*/
function reqToJson(req) {
return {
requestTime: Math.round(new Date().getTime()),
method: req.httpMethod,
headers: req.headers,
rawUrl: req.rawUrl,
body: req.body,
body: req.body || null,
multiPartFormData: null,
};
}
Expand Down
24 changes: 11 additions & 13 deletions src/Internal/Request.elm
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,15 @@ fakeRequest =

requestDecoder : Decode.Decoder RequestRecord
requestDecoder =
Decode.succeed RequestRecord
|> andMap
(Decode.field "requestTime"
(Decode.int |> Decode.map Time.millisToPosix)
)
|> andMap (Decode.field "method" Decode.string)
|> andMap (Decode.field "body" (Decode.nullable Decode.string))
|> andMap
(Decode.string
|> Decode.field "rawUrl"
)
|> andMap (Decode.field "headers" (Decode.dict Decode.string))
|> andMap
Decode.map6 RequestRecord
(Decode.field "requestTime"
(Decode.int |> Decode.map Time.millisToPosix)
)
(Decode.field "method" Decode.string)
(Decode.maybe (Decode.field "body" Decode.string))
(Decode.field "rawUrl" Decode.string)
(Decode.maybe (Decode.field "headers" (Decode.dict Decode.string)) |> Decode.map (Maybe.withDefault Dict.empty))
(Decode.maybe
(Decode.field "headers"
(optionalField "cookie" Decode.string
|> Decode.map
Expand All @@ -62,6 +58,8 @@ requestDecoder =
)
)
)
|> Decode.map (Maybe.withDefault Dict.empty)
)


andMap : Decode.Decoder a -> Decode.Decoder (a -> b) -> Decode.Decoder b
Expand Down

0 comments on commit 3774147

Please sign in to comment.