Skip to content

Commit

Permalink
Use WebApi for Response construction
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sherman committed Dec 24, 2021
1 parent 00ddedd commit 9250839
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
25 changes: 8 additions & 17 deletions app/entry.server.res
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
module ResponseInit = {
type t

external make: {..} => t = "%identity"
}

// TODO: Swap out for Webapi.Fetch.Response when it supports construction
// See https://github.com/tinymce/rescript-webapi/issues/63
@new
external makeResponse: (Webapi.Fetch.BodyInit.t, ResponseInit.t) => Webapi.Fetch.Response.t =
"Response"
external castHeadersToInit: Webapi.Fetch.Headers.t => Webapi.Fetch.HeadersInit.t = "%identity"

let default = (request, responseStatusCode, responseHeaders, remixContext) => {
open Webapi
Expand All @@ -19,11 +9,12 @@ let default = (request, responseStatusCode, responseHeaders, remixContext) => {

responseHeaders->Fetch.Headers.set("Content-Type", "text/html")

makeResponse(
Fetch.BodyInit.make("<!DOCTYPE html>" ++ markup),
ResponseInit.make({
"status": responseStatusCode,
"headers": responseHeaders,
}),
Fetch.Response.makeWithInit(
"<!DOCTYPE html>" ++ markup,
Fetch.ResponseInit.make(
~status=responseStatusCode,
~headers=responseHeaders->castHeadersToInit,
(),
),
)
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"remix": "^1.1.1",
"rescript-webapi": "^0.2.0"
"rescript-webapi": "^0.3.0"
},
"devDependencies": {
"@remix-run/dev": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module.exports = {
serverBuildDirectory: "build",
devServerPort: 8002,
ignoredRouteFiles: [".*", "*.res"],
transpileModules: ["rescript"]
transpileModules: ["rescript", "rescript-webapi"]
};

0 comments on commit 9250839

Please sign in to comment.