elm-pages 3.0.0-beta.32 → 3.0.0-beta.34
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/codegen/elm-pages-codegen.cjs +10 -78
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/dead-code-review/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm.json +1 -1
- package/generator/src/RouteBuilder.elm +2 -2
- package/generator/src/compatibility-key.js +2 -2
- package/generator/src/render.js +1 -0
- package/generator/src/request-cache.js +20 -6
- package/generator/static-code/elm-pages.js +10 -0
- package/package.json +3 -3
- package/src/BackendTask/Http.elm +8 -2
- package/src/Internal/Field.elm +19 -0
- package/src/Internal/Input.elm +81 -0
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/Internal/Msg.elm +70 -61
- package/src/Pages/Internal/Platform/Cli.elm +423 -425
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +1 -5
- package/src/Pages/Internal/Platform.elm +119 -100
- package/src/Pages/ProgramConfig.elm +12 -5
- package/src/Pages/StaticHttpRequest.elm +0 -1
- package/src/Pages/Transition.elm +9 -1
- package/src/PagesMsg.elm +0 -10
- package/src/RequestsAndPending.elm +31 -3
- package/src/Scaffold/Form.elm +9 -9
- package/src/Server/Request.elm +57 -61
- package/src/Form/Field.elm +0 -729
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -497
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1558
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -257
- package/src/Pages/Internal/Form.elm +0 -37
|
@@ -388,448 +388,446 @@ initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as rende
|
|
|
388
388
|
|
|
389
389
|
staticResponsesNew : BackendTask FatalError Effect
|
|
390
390
|
staticResponsesNew =
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
391
|
+
case singleRequest of
|
|
392
|
+
RenderRequest.Page serverRequestPayload ->
|
|
393
|
+
let
|
|
394
|
+
isAction : Maybe ActionRequest
|
|
395
|
+
isAction =
|
|
396
|
+
renderRequest
|
|
397
|
+
|> RenderRequest.maybeRequestPayload
|
|
398
|
+
|> Maybe.andThen (Decode.decodeValue isActionDecoder >> Result.withDefault Nothing)
|
|
399
|
+
|
|
400
|
+
currentUrl : Url
|
|
401
|
+
currentUrl =
|
|
402
|
+
{ protocol = Url.Https
|
|
403
|
+
, host = site.canonicalUrl
|
|
404
|
+
, port_ = Nothing
|
|
405
|
+
, path = serverRequestPayload.path |> Path.toRelative
|
|
406
|
+
, query = Nothing
|
|
407
|
+
, fragment = Nothing
|
|
408
|
+
}
|
|
409
|
+
in
|
|
410
|
+
--case isAction of
|
|
411
|
+
-- Just actionRequest ->
|
|
412
|
+
(if isDevServer then
|
|
413
|
+
config.handleRoute serverRequestPayload.frontmatter
|
|
414
|
+
|
|
415
|
+
else
|
|
416
|
+
BackendTask.succeed Nothing
|
|
417
|
+
)
|
|
418
|
+
|> BackendTask.andThen
|
|
419
|
+
(\pageFound ->
|
|
420
|
+
case pageFound of
|
|
421
|
+
Nothing ->
|
|
422
|
+
--sendSinglePageProgress site model.allRawResponses config model payload
|
|
423
|
+
(case isAction of
|
|
424
|
+
Just _ ->
|
|
425
|
+
config.action (RenderRequest.maybeRequestPayload renderRequest |> Maybe.withDefault Json.Encode.null) serverRequestPayload.frontmatter |> BackendTask.map Just
|
|
415
426
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
Nothing
|
|
487
|
-
|
|
488
|
-
pageModel : userModel
|
|
489
|
-
pageModel =
|
|
490
|
-
config.init
|
|
491
|
-
Pages.Flags.PreRenderFlags
|
|
492
|
-
sharedData
|
|
493
|
-
pageData_
|
|
494
|
-
maybeActionData
|
|
495
|
-
(Just
|
|
496
|
-
{ path =
|
|
497
|
-
{ path = currentPage.path
|
|
498
|
-
, query = Nothing
|
|
499
|
-
, fragment = Nothing
|
|
500
|
-
}
|
|
501
|
-
, metadata = currentPage.route
|
|
502
|
-
, pageUrl = Nothing
|
|
427
|
+
Nothing ->
|
|
428
|
+
BackendTask.succeed Nothing
|
|
429
|
+
)
|
|
430
|
+
|> BackendTask.andThen
|
|
431
|
+
(\something ->
|
|
432
|
+
let
|
|
433
|
+
actionHeaders2 : Maybe { statusCode : Int, headers : List ( String, String ) }
|
|
434
|
+
actionHeaders2 =
|
|
435
|
+
case something of
|
|
436
|
+
Just (PageServerResponse.RenderPage responseThing _) ->
|
|
437
|
+
Just responseThing
|
|
438
|
+
|
|
439
|
+
Just (PageServerResponse.ServerResponse responseThing) ->
|
|
440
|
+
Just
|
|
441
|
+
{ headers = responseThing.headers
|
|
442
|
+
, statusCode = responseThing.statusCode
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
_ ->
|
|
446
|
+
Nothing
|
|
447
|
+
|
|
448
|
+
maybeRedirectResponse : Maybe Effect
|
|
449
|
+
maybeRedirectResponse =
|
|
450
|
+
actionHeaders2
|
|
451
|
+
|> Maybe.andThen
|
|
452
|
+
(\responseMetadata ->
|
|
453
|
+
toRedirectResponse config
|
|
454
|
+
serverRequestPayload
|
|
455
|
+
includeHtml
|
|
456
|
+
responseMetadata
|
|
457
|
+
responseMetadata
|
|
458
|
+
)
|
|
459
|
+
in
|
|
460
|
+
case maybeRedirectResponse of
|
|
461
|
+
Just redirectResponse ->
|
|
462
|
+
redirectResponse
|
|
463
|
+
|> BackendTask.succeed
|
|
464
|
+
|
|
465
|
+
Nothing ->
|
|
466
|
+
BackendTask.map3
|
|
467
|
+
(\pageData sharedData tags ->
|
|
468
|
+
let
|
|
469
|
+
renderedResult : Effect
|
|
470
|
+
renderedResult =
|
|
471
|
+
case pageData of
|
|
472
|
+
PageServerResponse.RenderPage responseInfo pageData_ ->
|
|
473
|
+
let
|
|
474
|
+
currentPage : { path : Path, route : route }
|
|
475
|
+
currentPage =
|
|
476
|
+
{ path = serverRequestPayload.path, route = urlToRoute config currentUrl }
|
|
477
|
+
|
|
478
|
+
maybeActionData : Maybe actionData
|
|
479
|
+
maybeActionData =
|
|
480
|
+
case something of
|
|
481
|
+
Just (PageServerResponse.RenderPage _ actionThing) ->
|
|
482
|
+
Just actionThing
|
|
483
|
+
|
|
484
|
+
_ ->
|
|
485
|
+
Nothing
|
|
486
|
+
|
|
487
|
+
pageModel : userModel
|
|
488
|
+
pageModel =
|
|
489
|
+
config.init
|
|
490
|
+
Pages.Flags.PreRenderFlags
|
|
491
|
+
sharedData
|
|
492
|
+
pageData_
|
|
493
|
+
maybeActionData
|
|
494
|
+
(Just
|
|
495
|
+
{ path =
|
|
496
|
+
{ path = currentPage.path
|
|
497
|
+
, query = Nothing
|
|
498
|
+
, fragment = Nothing
|
|
503
499
|
}
|
|
500
|
+
, metadata = currentPage.route
|
|
501
|
+
, pageUrl = Nothing
|
|
502
|
+
}
|
|
503
|
+
)
|
|
504
|
+
|> Tuple.first
|
|
505
|
+
|
|
506
|
+
viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
|
|
507
|
+
viewValue =
|
|
508
|
+
(config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData_ maybeActionData |> .view) pageModel
|
|
509
|
+
|
|
510
|
+
responseMetadata : { statusCode : Int, headers : List ( String, String ) }
|
|
511
|
+
responseMetadata =
|
|
512
|
+
actionHeaders2 |> Maybe.withDefault responseInfo
|
|
513
|
+
in
|
|
514
|
+
(case isAction of
|
|
515
|
+
Just actionRequestKind ->
|
|
516
|
+
let
|
|
517
|
+
actionDataResult : Maybe (PageServerResponse actionData errorPage)
|
|
518
|
+
actionDataResult =
|
|
519
|
+
something
|
|
520
|
+
in
|
|
521
|
+
case actionDataResult of
|
|
522
|
+
Just (PageServerResponse.RenderPage ignored2 actionData_) ->
|
|
523
|
+
case actionRequestKind of
|
|
524
|
+
ActionResponseRequest ->
|
|
525
|
+
( ignored2.headers
|
|
526
|
+
, ResponseSketch.HotUpdate pageData_ sharedData (Just actionData_)
|
|
527
|
+
|> config.encodeResponse
|
|
528
|
+
|> Bytes.Encode.encode
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
ActionOnlyRequest ->
|
|
532
|
+
---- TODO need to encode action data when only that is requested (not ResponseSketch?)
|
|
533
|
+
( ignored2.headers
|
|
534
|
+
, actionData_
|
|
535
|
+
|> config.encodeAction
|
|
536
|
+
|> Bytes.Encode.encode
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
_ ->
|
|
540
|
+
( responseMetadata.headers
|
|
541
|
+
, Bytes.Encode.encode (Bytes.Encode.unsignedInt8 0)
|
|
504
542
|
)
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
in
|
|
515
|
-
(case isAction of
|
|
516
|
-
Just actionRequestKind ->
|
|
543
|
+
|
|
544
|
+
Nothing ->
|
|
545
|
+
( responseMetadata.headers
|
|
546
|
+
, ResponseSketch.HotUpdate pageData_ sharedData Nothing
|
|
547
|
+
|> config.encodeResponse
|
|
548
|
+
|> Bytes.Encode.encode
|
|
549
|
+
)
|
|
550
|
+
)
|
|
551
|
+
|> (\( actionHeaders, byteEncodedPageData ) ->
|
|
517
552
|
let
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
553
|
+
rendered : { view : userModel -> { title : String, body : List (Html (PagesMsg userMsg)) }, head : List Tag }
|
|
554
|
+
rendered =
|
|
555
|
+
config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData_ maybeActionData
|
|
521
556
|
in
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|> Bytes.Encode.encode
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
ActionOnlyRequest ->
|
|
533
|
-
---- TODO need to encode action data when only that is requested (not ResponseSketch?)
|
|
534
|
-
( ignored2.headers
|
|
535
|
-
, actionData_
|
|
536
|
-
|> config.encodeAction
|
|
537
|
-
|> Bytes.Encode.encode
|
|
538
|
-
)
|
|
539
|
-
|
|
540
|
-
_ ->
|
|
541
|
-
( responseMetadata.headers
|
|
542
|
-
, Bytes.Encode.encode (Bytes.Encode.unsignedInt8 0)
|
|
557
|
+
PageServerResponse.toRedirect responseMetadata
|
|
558
|
+
|> Maybe.map
|
|
559
|
+
(\{ location } ->
|
|
560
|
+
location
|
|
561
|
+
|> ResponseSketch.Redirect
|
|
562
|
+
|> config.encodeResponse
|
|
563
|
+
|> Bytes.Encode.encode
|
|
543
564
|
)
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
)
|
|
566
|
-
-- TODO handle other cases besides redirects?
|
|
567
|
-
|> Maybe.withDefault byteEncodedPageData
|
|
568
|
-
|> (\encodedData ->
|
|
569
|
-
{ route = currentPage.path |> Path.toRelative
|
|
570
|
-
, contentJson = Dict.empty
|
|
571
|
-
, html = viewValue.body |> bodyToString
|
|
572
|
-
, errors = []
|
|
573
|
-
, head = rendered.head ++ tags
|
|
574
|
-
, title = viewValue.title
|
|
575
|
-
, staticHttpCache = Dict.empty
|
|
576
|
-
, is404 = False
|
|
577
|
-
, statusCode =
|
|
578
|
-
case includeHtml of
|
|
579
|
-
RenderRequest.OnlyJson ->
|
|
580
|
-
200
|
|
581
|
-
|
|
582
|
-
RenderRequest.HtmlAndJson ->
|
|
583
|
-
responseMetadata.statusCode
|
|
584
|
-
, headers =
|
|
585
|
-
-- 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?
|
|
586
|
-
actionHeaders
|
|
587
|
-
}
|
|
588
|
-
|> ToJsPayload.PageProgress
|
|
589
|
-
|> Effect.SendSinglePageNew encodedData
|
|
590
|
-
)
|
|
591
|
-
)
|
|
592
|
-
|
|
593
|
-
PageServerResponse.ServerResponse serverResponse ->
|
|
594
|
-
--PageServerResponse.ServerResponse serverResponse
|
|
595
|
-
-- TODO handle error?
|
|
596
|
-
let
|
|
597
|
-
responseMetadata : PageServerResponse.Response
|
|
598
|
-
responseMetadata =
|
|
599
|
-
case something of
|
|
600
|
-
Just (PageServerResponse.ServerResponse responseThing) ->
|
|
601
|
-
responseThing
|
|
602
|
-
|
|
603
|
-
_ ->
|
|
604
|
-
serverResponse
|
|
605
|
-
in
|
|
606
|
-
toRedirectResponse config serverRequestPayload includeHtml serverResponse responseMetadata
|
|
607
|
-
|> Maybe.withDefault
|
|
608
|
-
({ body = serverResponse |> PageServerResponse.toJson
|
|
609
|
-
, staticHttpCache = Dict.empty
|
|
610
|
-
, statusCode = serverResponse.statusCode
|
|
611
|
-
}
|
|
612
|
-
|> ToJsPayload.SendApiResponse
|
|
613
|
-
|> Effect.SendSinglePage
|
|
614
|
-
)
|
|
615
|
-
|
|
616
|
-
PageServerResponse.ErrorPage error record ->
|
|
617
|
-
let
|
|
618
|
-
currentPage : { path : Path, route : route }
|
|
619
|
-
currentPage =
|
|
620
|
-
{ path = serverRequestPayload.path, route = urlToRoute config currentUrl }
|
|
621
|
-
|
|
622
|
-
pageModel : userModel
|
|
623
|
-
pageModel =
|
|
624
|
-
config.init
|
|
625
|
-
Pages.Flags.PreRenderFlags
|
|
626
|
-
sharedData
|
|
627
|
-
pageData2
|
|
628
|
-
Nothing
|
|
629
|
-
(Just
|
|
630
|
-
{ path =
|
|
631
|
-
{ path = currentPage.path
|
|
632
|
-
, query = Nothing
|
|
633
|
-
, fragment = Nothing
|
|
565
|
+
-- TODO handle other cases besides redirects?
|
|
566
|
+
|> Maybe.withDefault byteEncodedPageData
|
|
567
|
+
|> (\encodedData ->
|
|
568
|
+
{ route = currentPage.path |> Path.toRelative
|
|
569
|
+
, contentJson = Dict.empty
|
|
570
|
+
, html = viewValue.body |> bodyToString
|
|
571
|
+
, errors = []
|
|
572
|
+
, head = rendered.head ++ tags
|
|
573
|
+
, title = viewValue.title
|
|
574
|
+
, staticHttpCache = Dict.empty
|
|
575
|
+
, is404 = False
|
|
576
|
+
, statusCode =
|
|
577
|
+
case includeHtml of
|
|
578
|
+
RenderRequest.OnlyJson ->
|
|
579
|
+
200
|
|
580
|
+
|
|
581
|
+
RenderRequest.HtmlAndJson ->
|
|
582
|
+
responseMetadata.statusCode
|
|
583
|
+
, headers =
|
|
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
|
+
actionHeaders
|
|
634
586
|
}
|
|
635
|
-
|
|
636
|
-
|
|
587
|
+
|> ToJsPayload.PageProgress
|
|
588
|
+
|> Effect.SendSinglePageNew encodedData
|
|
589
|
+
)
|
|
590
|
+
)
|
|
591
|
+
|
|
592
|
+
PageServerResponse.ServerResponse serverResponse ->
|
|
593
|
+
--PageServerResponse.ServerResponse serverResponse
|
|
594
|
+
-- TODO handle error?
|
|
595
|
+
let
|
|
596
|
+
responseMetadata : PageServerResponse.Response
|
|
597
|
+
responseMetadata =
|
|
598
|
+
case something of
|
|
599
|
+
Just (PageServerResponse.ServerResponse responseThing) ->
|
|
600
|
+
responseThing
|
|
601
|
+
|
|
602
|
+
_ ->
|
|
603
|
+
serverResponse
|
|
604
|
+
in
|
|
605
|
+
toRedirectResponse config serverRequestPayload includeHtml serverResponse responseMetadata
|
|
606
|
+
|> Maybe.withDefault
|
|
607
|
+
({ body = serverResponse |> PageServerResponse.toJson
|
|
608
|
+
, staticHttpCache = Dict.empty
|
|
609
|
+
, statusCode = serverResponse.statusCode
|
|
610
|
+
}
|
|
611
|
+
|> ToJsPayload.SendApiResponse
|
|
612
|
+
|> Effect.SendSinglePage
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
PageServerResponse.ErrorPage error record ->
|
|
616
|
+
let
|
|
617
|
+
currentPage : { path : Path, route : route }
|
|
618
|
+
currentPage =
|
|
619
|
+
{ path = serverRequestPayload.path, route = urlToRoute config currentUrl }
|
|
620
|
+
|
|
621
|
+
pageModel : userModel
|
|
622
|
+
pageModel =
|
|
623
|
+
config.init
|
|
624
|
+
Pages.Flags.PreRenderFlags
|
|
625
|
+
sharedData
|
|
626
|
+
pageData2
|
|
627
|
+
Nothing
|
|
628
|
+
(Just
|
|
629
|
+
{ path =
|
|
630
|
+
{ path = currentPage.path
|
|
631
|
+
, query = Nothing
|
|
632
|
+
, fragment = Nothing
|
|
637
633
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
pageData2 : pageData
|
|
642
|
-
pageData2 =
|
|
643
|
-
config.errorPageToData error
|
|
644
|
-
|
|
645
|
-
viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
|
|
646
|
-
viewValue =
|
|
647
|
-
(config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData2 Nothing |> .view) pageModel
|
|
648
|
-
in
|
|
649
|
-
(ResponseSketch.HotUpdate pageData2 sharedData Nothing
|
|
650
|
-
|> config.encodeResponse
|
|
651
|
-
|> Bytes.Encode.encode
|
|
652
|
-
)
|
|
653
|
-
|> (\encodedData ->
|
|
654
|
-
{ route = currentPage.path |> Path.toRelative
|
|
655
|
-
, contentJson = Dict.empty
|
|
656
|
-
, html = viewValue.body |> bodyToString
|
|
657
|
-
, errors = []
|
|
658
|
-
, head = tags
|
|
659
|
-
, title = viewValue.title
|
|
660
|
-
, staticHttpCache = Dict.empty
|
|
661
|
-
, is404 = False
|
|
662
|
-
, statusCode =
|
|
663
|
-
case includeHtml of
|
|
664
|
-
RenderRequest.OnlyJson ->
|
|
665
|
-
200
|
|
666
|
-
|
|
667
|
-
RenderRequest.HtmlAndJson ->
|
|
668
|
-
config.errorStatusCode error
|
|
669
|
-
, headers = record.headers
|
|
634
|
+
, metadata = currentPage.route
|
|
635
|
+
, pageUrl = Nothing
|
|
670
636
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
isPreRendered =
|
|
686
|
-
let
|
|
687
|
-
keys : Int
|
|
688
|
-
keys =
|
|
689
|
-
RenderRequest.maybeRequestPayload renderRequest |> Maybe.map (Decode.decodeValue (Decode.keyValuePairs Decode.value)) |> Maybe.withDefault (Ok []) |> Result.withDefault [] |> List.map Tuple.first |> List.length
|
|
690
|
-
in
|
|
691
|
-
-- TODO this is a bit hacky, would be nice to clean up the way of checking whether this is server-rendered or pre-rendered
|
|
692
|
-
keys <= 1
|
|
693
|
-
in
|
|
694
|
-
if isDevServer || isPreRendered then
|
|
695
|
-
-- we want to stop the build for pre-rendered routes, and give a dev server error popup in the dev server
|
|
696
|
-
BackendTask.fail error
|
|
697
|
-
|
|
698
|
-
else
|
|
699
|
-
--only render the production ErrorPage in production server-rendered Routes
|
|
700
|
-
config.sharedData
|
|
701
|
-
|> BackendTask.andThen
|
|
702
|
-
(\justSharedData ->
|
|
703
|
-
let
|
|
704
|
-
errorPage : errorPage
|
|
705
|
-
errorPage =
|
|
706
|
-
config.internalError fatalError.body
|
|
707
|
-
|
|
708
|
-
dataThing : pageData
|
|
709
|
-
dataThing =
|
|
710
|
-
errorPage
|
|
711
|
-
|> config.errorPageToData
|
|
712
|
-
|
|
713
|
-
statusCode : Int
|
|
714
|
-
statusCode =
|
|
715
|
-
config.errorStatusCode errorPage
|
|
716
|
-
|
|
717
|
-
byteEncodedPageData : Bytes
|
|
718
|
-
byteEncodedPageData =
|
|
719
|
-
ResponseSketch.HotUpdate
|
|
720
|
-
dataThing
|
|
721
|
-
justSharedData
|
|
722
|
-
-- TODO remove shared action data
|
|
723
|
-
Nothing
|
|
724
|
-
|> config.encodeResponse
|
|
725
|
-
|> Bytes.Encode.encode
|
|
726
|
-
|
|
727
|
-
pageModel : userModel
|
|
728
|
-
pageModel =
|
|
729
|
-
config.init
|
|
730
|
-
Pages.Flags.PreRenderFlags
|
|
731
|
-
justSharedData
|
|
732
|
-
dataThing
|
|
733
|
-
Nothing
|
|
734
|
-
(Just
|
|
735
|
-
{ path =
|
|
736
|
-
{ path = currentPage.path
|
|
737
|
-
, query = Nothing
|
|
738
|
-
, fragment = Nothing
|
|
739
|
-
}
|
|
740
|
-
, metadata = currentPage.route
|
|
741
|
-
, pageUrl = Nothing
|
|
742
|
-
}
|
|
637
|
+
)
|
|
638
|
+
|> Tuple.first
|
|
639
|
+
|
|
640
|
+
pageData2 : pageData
|
|
641
|
+
pageData2 =
|
|
642
|
+
config.errorPageToData error
|
|
643
|
+
|
|
644
|
+
viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
|
|
645
|
+
viewValue =
|
|
646
|
+
(config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData2 Nothing |> .view) pageModel
|
|
647
|
+
in
|
|
648
|
+
(ResponseSketch.HotUpdate pageData2 sharedData Nothing
|
|
649
|
+
|> config.encodeResponse
|
|
650
|
+
|> Bytes.Encode.encode
|
|
743
651
|
)
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
652
|
+
|> (\encodedData ->
|
|
653
|
+
{ route = currentPage.path |> Path.toRelative
|
|
654
|
+
, contentJson = Dict.empty
|
|
655
|
+
, html = viewValue.body |> bodyToString
|
|
656
|
+
, errors = []
|
|
657
|
+
, head = tags
|
|
658
|
+
, title = viewValue.title
|
|
659
|
+
, staticHttpCache = Dict.empty
|
|
660
|
+
, is404 = False
|
|
661
|
+
, statusCode =
|
|
662
|
+
case includeHtml of
|
|
663
|
+
RenderRequest.OnlyJson ->
|
|
664
|
+
200
|
|
665
|
+
|
|
666
|
+
RenderRequest.HtmlAndJson ->
|
|
667
|
+
config.errorStatusCode error
|
|
668
|
+
, headers = record.headers
|
|
669
|
+
}
|
|
670
|
+
|> ToJsPayload.PageProgress
|
|
671
|
+
|> Effect.SendSinglePageNew encodedData
|
|
672
|
+
)
|
|
673
|
+
in
|
|
674
|
+
renderedResult
|
|
675
|
+
)
|
|
676
|
+
(config.data (RenderRequest.maybeRequestPayload renderRequest |> Maybe.withDefault Json.Encode.null) serverRequestPayload.frontmatter)
|
|
677
|
+
config.sharedData
|
|
678
|
+
globalHeadTags
|
|
679
|
+
)
|
|
680
|
+
|> BackendTask.onError
|
|
681
|
+
(\((Pages.Internal.FatalError.FatalError fatalError) as error) ->
|
|
682
|
+
let
|
|
683
|
+
isPreRendered : Bool
|
|
684
|
+
isPreRendered =
|
|
685
|
+
let
|
|
686
|
+
keys : Int
|
|
687
|
+
keys =
|
|
688
|
+
RenderRequest.maybeRequestPayload renderRequest |> Maybe.map (Decode.decodeValue (Decode.keyValuePairs Decode.value)) |> Maybe.withDefault (Ok []) |> Result.withDefault [] |> List.map Tuple.first |> List.length
|
|
689
|
+
in
|
|
690
|
+
-- TODO this is a bit hacky, would be nice to clean up the way of checking whether this is server-rendered or pre-rendered
|
|
691
|
+
keys <= 1
|
|
692
|
+
in
|
|
693
|
+
if isDevServer || isPreRendered then
|
|
694
|
+
-- we want to stop the build for pre-rendered routes, and give a dev server error popup in the dev server
|
|
695
|
+
BackendTask.fail error
|
|
696
|
+
|
|
697
|
+
else
|
|
698
|
+
--only render the production ErrorPage in production server-rendered Routes
|
|
699
|
+
config.sharedData
|
|
700
|
+
|> BackendTask.andThen
|
|
701
|
+
(\justSharedData ->
|
|
702
|
+
let
|
|
703
|
+
errorPage : errorPage
|
|
704
|
+
errorPage =
|
|
705
|
+
config.internalError fatalError.body
|
|
706
|
+
|
|
707
|
+
dataThing : pageData
|
|
708
|
+
dataThing =
|
|
709
|
+
errorPage
|
|
710
|
+
|> config.errorPageToData
|
|
711
|
+
|
|
712
|
+
statusCode : Int
|
|
713
|
+
statusCode =
|
|
714
|
+
config.errorStatusCode errorPage
|
|
715
|
+
|
|
716
|
+
byteEncodedPageData : Bytes
|
|
717
|
+
byteEncodedPageData =
|
|
718
|
+
ResponseSketch.HotUpdate
|
|
719
|
+
dataThing
|
|
720
|
+
justSharedData
|
|
721
|
+
-- TODO remove shared action data
|
|
722
|
+
Nothing
|
|
723
|
+
|> config.encodeResponse
|
|
724
|
+
|> Bytes.Encode.encode
|
|
725
|
+
|
|
726
|
+
pageModel : userModel
|
|
727
|
+
pageModel =
|
|
728
|
+
config.init
|
|
729
|
+
Pages.Flags.PreRenderFlags
|
|
730
|
+
justSharedData
|
|
731
|
+
dataThing
|
|
732
|
+
Nothing
|
|
733
|
+
(Just
|
|
734
|
+
{ path =
|
|
735
|
+
{ path = currentPage.path
|
|
736
|
+
, query = Nothing
|
|
737
|
+
, fragment = Nothing
|
|
738
|
+
}
|
|
739
|
+
, metadata = currentPage.route
|
|
740
|
+
, pageUrl = Nothing
|
|
741
|
+
}
|
|
742
|
+
)
|
|
743
|
+
|> Tuple.first
|
|
744
|
+
|
|
745
|
+
currentPage : { path : Path, route : route }
|
|
746
|
+
currentPage =
|
|
747
|
+
{ path = serverRequestPayload.path, route = urlToRoute config currentUrl }
|
|
748
|
+
|
|
749
|
+
viewValue : { title : String, body : List (Html (PagesMsg userMsg)) }
|
|
750
|
+
viewValue =
|
|
751
|
+
(config.view Dict.empty Dict.empty Nothing currentPage Nothing justSharedData dataThing Nothing |> .view)
|
|
752
|
+
pageModel
|
|
753
|
+
in
|
|
754
|
+
{ route = Path.toAbsolute currentPage.path
|
|
755
|
+
, contentJson = Dict.empty
|
|
756
|
+
, html = viewValue.body |> bodyToString
|
|
757
|
+
, errors = []
|
|
758
|
+
, head = [] -- TODO render head tags --config.view Dict.empty Dict.empty Nothing pathAndRoute Nothing justSharedData pageData Nothing |> .head
|
|
759
|
+
, title = viewValue.title
|
|
760
|
+
, staticHttpCache = Dict.empty
|
|
761
|
+
, is404 = False
|
|
762
|
+
, statusCode = statusCode
|
|
763
|
+
, headers = []
|
|
764
|
+
}
|
|
765
|
+
|> ToJsPayload.PageProgress
|
|
766
|
+
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
767
|
+
|> BackendTask.succeed
|
|
768
|
+
)
|
|
769
|
+
)
|
|
794
770
|
|
|
795
|
-
|
|
771
|
+
Just notFoundReason ->
|
|
796
772
|
render404Page config
|
|
797
|
-
-- TODO do I need sharedDataResult here?
|
|
798
773
|
Nothing
|
|
774
|
+
-- TODO do I need sharedDataResult?
|
|
775
|
+
--(Result.toMaybe sharedDataResult)
|
|
799
776
|
isDevServer
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
-- [ error ]
|
|
804
|
-
-- |> ToJsPayload.Errors
|
|
805
|
-
-- |> Effect.SendSinglePage
|
|
777
|
+
serverRequestPayload.path
|
|
778
|
+
notFoundReason
|
|
779
|
+
|> BackendTask.succeed
|
|
806
780
|
)
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
781
|
+
|
|
782
|
+
RenderRequest.Api ( path, ApiRoute apiHandler ) ->
|
|
783
|
+
BackendTask.map2
|
|
784
|
+
(\response _ ->
|
|
785
|
+
case response of
|
|
786
|
+
Just okResponse ->
|
|
787
|
+
{ body = okResponse
|
|
788
|
+
, staticHttpCache = Dict.empty -- TODO do I need to serialize the full cache here, or can I handle that from the JS side?
|
|
789
|
+
, statusCode = 200
|
|
790
|
+
}
|
|
791
|
+
|> ToJsPayload.SendApiResponse
|
|
792
|
+
|> Effect.SendSinglePage
|
|
793
|
+
|
|
794
|
+
Nothing ->
|
|
795
|
+
render404Page config
|
|
796
|
+
-- TODO do I need sharedDataResult here?
|
|
797
|
+
Nothing
|
|
798
|
+
isDevServer
|
|
799
|
+
(Path.fromString path)
|
|
800
|
+
NotFoundReason.NoMatchingRoute
|
|
801
|
+
--Err error ->
|
|
802
|
+
-- [ error ]
|
|
803
|
+
-- |> ToJsPayload.Errors
|
|
804
|
+
-- |> Effect.SendSinglePage
|
|
805
|
+
)
|
|
806
|
+
(apiHandler.matchesToResponse
|
|
807
|
+
(renderRequest
|
|
808
|
+
|> RenderRequest.maybeRequestPayload
|
|
809
|
+
|> Maybe.withDefault Json.Encode.null
|
|
826
810
|
)
|
|
827
|
-
|
|
828
|
-
globalHeadTags
|
|
829
|
-
-- TODO is there a way to resolve sharedData but get it as a Result if it fails?
|
|
830
|
-
--config.sharedData
|
|
811
|
+
path
|
|
831
812
|
)
|
|
832
|
-
|
|
813
|
+
globalHeadTags
|
|
814
|
+
|
|
815
|
+
RenderRequest.NotFound notFoundPath ->
|
|
816
|
+
(BackendTask.map2
|
|
817
|
+
(\_ _ ->
|
|
818
|
+
render404Page config
|
|
819
|
+
Nothing
|
|
820
|
+
--(Result.toMaybe sharedDataResult)
|
|
821
|
+
--model
|
|
822
|
+
isDevServer
|
|
823
|
+
notFoundPath
|
|
824
|
+
NotFoundReason.NoMatchingRoute
|
|
825
|
+
)
|
|
826
|
+
(BackendTask.succeed [])
|
|
827
|
+
globalHeadTags
|
|
828
|
+
-- TODO is there a way to resolve sharedData but get it as a Result if it fails?
|
|
829
|
+
--config.sharedData
|
|
830
|
+
)
|
|
833
831
|
|
|
834
832
|
initialModel : Model route
|
|
835
833
|
initialModel =
|