elm-pages 3.0.0-beta.39 → 3.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/adapter/netlify.js +8 -10
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/dev-server.js +13 -5
- package/package.json +1 -1
- package/src/Pages/Internal/Platform/Cli.elm +22 -6
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/ToJsPayload.elm +2 -2
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ https://github.com/dillonkearns/elm-pages/projects
|
|
|
81
81
|
You will see an error if the NPM and Elm package do not have a matching Compatibility Key. Usually it's best to upgrade to the latest version of both the Elm and NPM
|
|
82
82
|
packages when you upgrade. However, in case you want to install versions that are behind the latest, the Compatibility Key is included here for reference.
|
|
83
83
|
|
|
84
|
-
Current Compatibility Key:
|
|
84
|
+
Current Compatibility Key: 17.
|
|
85
85
|
|
|
86
86
|
## Contributors ✨
|
|
87
87
|
|
package/adapter/netlify.js
CHANGED
|
@@ -108,17 +108,15 @@ export const handler = render;`
|
|
|
108
108
|
async function render(event, context) {
|
|
109
109
|
try {
|
|
110
110
|
const renderResult = await elmPages.render(await reqToJson(event));
|
|
111
|
-
|
|
112
|
-
const statusCode = renderResult.statusCode;
|
|
113
|
-
const headers = renderResult.headers;
|
|
111
|
+
const { headers, statusCode } = renderResult;
|
|
114
112
|
|
|
115
113
|
if (renderResult.kind === "bytes") {
|
|
116
114
|
return {
|
|
117
115
|
body: Buffer.from(renderResult.body).toString("base64"),
|
|
118
116
|
isBase64Encoded: true,
|
|
119
117
|
multiValueHeaders: {
|
|
120
|
-
"Content-Type": "application/octet-stream",
|
|
121
|
-
"x-powered-by": "elm-pages",
|
|
118
|
+
"Content-Type": ["application/octet-stream"],
|
|
119
|
+
"x-powered-by": ["elm-pages"],
|
|
122
120
|
...headers,
|
|
123
121
|
},
|
|
124
122
|
statusCode,
|
|
@@ -134,8 +132,8 @@ async function render(event, context) {
|
|
|
134
132
|
return {
|
|
135
133
|
body: renderResult.body,
|
|
136
134
|
multiValueHeaders: {
|
|
137
|
-
"Content-Type": "text/html",
|
|
138
|
-
"x-powered-by": "elm-pages",
|
|
135
|
+
"Content-Type": ["text/html"],
|
|
136
|
+
"x-powered-by": ["elm-pages"],
|
|
139
137
|
...headers,
|
|
140
138
|
},
|
|
141
139
|
statusCode,
|
|
@@ -147,9 +145,9 @@ async function render(event, context) {
|
|
|
147
145
|
return {
|
|
148
146
|
body: \`<body><h1>Error</h1><pre>\${JSON.stringify(error, null, 2)}</pre></body>\`,
|
|
149
147
|
statusCode: 500,
|
|
150
|
-
|
|
151
|
-
"Content-Type": "text/html",
|
|
152
|
-
"x-powered-by": "elm-pages",
|
|
148
|
+
multiValueHeaders: {
|
|
149
|
+
"Content-Type": ["text/html"],
|
|
150
|
+
"x-powered-by": ["elm-pages"],
|
|
153
151
|
},
|
|
154
152
|
};
|
|
155
153
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const compatibilityKey =
|
|
1
|
+
export const compatibilityKey = 17;
|
|
2
2
|
|
|
3
|
-
export const packageVersion = "3.0.0-beta.
|
|
3
|
+
export const packageVersion = "3.0.0-beta.40";
|
|
@@ -534,9 +534,9 @@ export async function start(options) {
|
|
|
534
534
|
/<!-- ROOT -->\S*<html lang="en">/m,
|
|
535
535
|
info.rootElement
|
|
536
536
|
);
|
|
537
|
+
setHeaders(res, renderResult.headers);
|
|
537
538
|
res.writeHead(renderResult.statusCode, {
|
|
538
539
|
"Content-Type": "text/html",
|
|
539
|
-
...renderResult.headers,
|
|
540
540
|
});
|
|
541
541
|
res.end(renderedHtml);
|
|
542
542
|
} catch (e) {
|
|
@@ -548,10 +548,8 @@ export async function start(options) {
|
|
|
548
548
|
case "api-response": {
|
|
549
549
|
if (renderResult.body.kind === "server-response") {
|
|
550
550
|
const serverResponse = renderResult.body;
|
|
551
|
-
res.
|
|
552
|
-
|
|
553
|
-
serverResponse.headers
|
|
554
|
-
);
|
|
551
|
+
setHeaders(res, serverResponse.headers);
|
|
552
|
+
res.writeHead(serverResponse.statusCode);
|
|
555
553
|
res.end(serverResponse.body);
|
|
556
554
|
} else if (renderResult.body.kind === "static-file") {
|
|
557
555
|
let mimeType = serveStatic.mime.lookup(pathname || "text/html");
|
|
@@ -594,6 +592,16 @@ export async function start(options) {
|
|
|
594
592
|
});
|
|
595
593
|
}
|
|
596
594
|
|
|
595
|
+
/**
|
|
596
|
+
* @param { http.ServerResponse } res
|
|
597
|
+
* @param {{ [key: string]: string[]; }} headers
|
|
598
|
+
*/
|
|
599
|
+
function setHeaders(res, headers) {
|
|
600
|
+
Object.keys(headers).forEach(function (key) {
|
|
601
|
+
res.setHeader(key, headers[key]);
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
|
|
597
605
|
/**
|
|
598
606
|
* @param {string} reviewReportJsonString
|
|
599
607
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elm-pages",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.40",
|
|
5
5
|
"homepage": "https://elm-pages.com",
|
|
6
6
|
"moduleResolution": "node",
|
|
7
7
|
"description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
|
|
@@ -11,7 +11,7 @@ import BuildError exposing (BuildError)
|
|
|
11
11
|
import Bytes exposing (Bytes)
|
|
12
12
|
import Bytes.Encode
|
|
13
13
|
import Codec
|
|
14
|
-
import Dict
|
|
14
|
+
import Dict exposing (Dict)
|
|
15
15
|
import FatalError exposing (FatalError)
|
|
16
16
|
import Head exposing (Tag)
|
|
17
17
|
import Html exposing (Html)
|
|
@@ -583,6 +583,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
|
|
|
583
583
|
, headers =
|
|
584
584
|
-- TODO should `responseInfo.headers` be used? Is there a problem in the case where there is both an action and data response in one? Do we need to make sure it is performed as two separate HTTP requests to ensure that the cookies are set correctly in that case?
|
|
585
585
|
actionHeaders
|
|
586
|
+
|> combineHeaders
|
|
586
587
|
}
|
|
587
588
|
|> ToJsPayload.PageProgress
|
|
588
589
|
|> Effect.SendSinglePageNew encodedData
|
|
@@ -665,7 +666,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
|
|
|
665
666
|
|
|
666
667
|
RenderRequest.HtmlAndJson ->
|
|
667
668
|
config.errorStatusCode error
|
|
668
|
-
, headers = record.headers
|
|
669
|
+
, headers = record.headers |> combineHeaders
|
|
669
670
|
}
|
|
670
671
|
|> ToJsPayload.PageProgress
|
|
671
672
|
|> Effect.SendSinglePageNew encodedData
|
|
@@ -760,7 +761,7 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
|
|
|
760
761
|
, staticHttpCache = Dict.empty
|
|
761
762
|
, is404 = False
|
|
762
763
|
, statusCode = statusCode
|
|
763
|
-
, headers =
|
|
764
|
+
, headers = Dict.empty
|
|
764
765
|
}
|
|
765
766
|
|> ToJsPayload.PageProgress
|
|
766
767
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
@@ -966,7 +967,7 @@ render404Page config sharedData isDevServer path notFoundReason =
|
|
|
966
967
|
, staticHttpCache = Dict.empty
|
|
967
968
|
, is404 = True
|
|
968
969
|
, statusCode = 404
|
|
969
|
-
, headers =
|
|
970
|
+
, headers = Dict.empty
|
|
970
971
|
}
|
|
971
972
|
|> ToJsPayload.PageProgress
|
|
972
973
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
@@ -998,7 +999,7 @@ render404Page config sharedData isDevServer path notFoundReason =
|
|
|
998
999
|
--model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
|
|
999
1000
|
, is404 = True
|
|
1000
1001
|
, statusCode = 404
|
|
1001
|
-
, headers =
|
|
1002
|
+
, headers = Dict.empty
|
|
1002
1003
|
}
|
|
1003
1004
|
|> ToJsPayload.PageProgress
|
|
1004
1005
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
@@ -1059,8 +1060,23 @@ toRedirectResponse config serverRequestPayload includeHtml serverResponse respon
|
|
|
1059
1060
|
|
|
1060
1061
|
RenderRequest.HtmlAndJson ->
|
|
1061
1062
|
responseMetadata.statusCode
|
|
1062
|
-
, headers = responseMetadata.headers
|
|
1063
|
+
, headers = responseMetadata.headers |> combineHeaders
|
|
1063
1064
|
}
|
|
1064
1065
|
|> ToJsPayload.PageProgress
|
|
1065
1066
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
1066
1067
|
)
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
combineHeaders : List ( String, String ) -> Dict String (List String)
|
|
1071
|
+
combineHeaders headers =
|
|
1072
|
+
headers
|
|
1073
|
+
|> List.foldl
|
|
1074
|
+
(\( key, value ) dict ->
|
|
1075
|
+
Dict.update key
|
|
1076
|
+
(Maybe.map ((::) value)
|
|
1077
|
+
>> Maybe.withDefault [ value ]
|
|
1078
|
+
>> Just
|
|
1079
|
+
)
|
|
1080
|
+
dict
|
|
1081
|
+
)
|
|
1082
|
+
Dict.empty
|
|
@@ -25,7 +25,7 @@ type alias ToJsSuccessPayloadNew =
|
|
|
25
25
|
, staticHttpCache : Dict String String
|
|
26
26
|
, is404 : Bool
|
|
27
27
|
, statusCode : Int
|
|
28
|
-
, headers :
|
|
28
|
+
, headers : Dict String (List String)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
@@ -76,7 +76,7 @@ successCodecNew canonicalSiteUrl currentPagePath =
|
|
|
76
76
|
|> Codec.field "statusCode" .statusCode Codec.int
|
|
77
77
|
|> Codec.field "headers"
|
|
78
78
|
.headers
|
|
79
|
-
(Codec.dict Codec.
|
|
79
|
+
(Codec.dict (Codec.list Codec.string))
|
|
80
80
|
|> Codec.buildObject
|
|
81
81
|
|
|
82
82
|
|