2021-12-16 07:10:54 +03:00
|
|
|
module Page.Time exposing (Data, Model, Msg, page)
|
|
|
|
|
|
|
|
import DataSource exposing (DataSource)
|
|
|
|
import Dict exposing (Dict)
|
|
|
|
import Head
|
|
|
|
import Head.Seo as Seo
|
|
|
|
import Html
|
|
|
|
import Page exposing (Page, PageWithState, StaticPayload)
|
2021-12-21 22:58:12 +03:00
|
|
|
import PageServerResponse exposing (PageServerResponse)
|
2021-12-16 07:10:54 +03:00
|
|
|
import Pages.PageUrl exposing (PageUrl)
|
|
|
|
import Pages.Url
|
2021-12-27 08:56:33 +03:00
|
|
|
import Server.Request as Request
|
2022-01-01 03:15:41 +03:00
|
|
|
import Server.Response
|
2021-12-16 07:10:54 +03:00
|
|
|
import Shared
|
|
|
|
import Url
|
|
|
|
import View exposing (View)
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Msg =
|
|
|
|
Never
|
|
|
|
|
|
|
|
|
|
|
|
type alias RouteParams =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
page : Page RouteParams Data
|
|
|
|
page =
|
2021-12-24 00:34:19 +03:00
|
|
|
Page.serverRender
|
2021-12-16 07:10:54 +03:00
|
|
|
{ head = head
|
|
|
|
, data = data
|
|
|
|
}
|
|
|
|
|> Page.buildNoState { view = view }
|
|
|
|
|
|
|
|
|
|
|
|
type alias Request =
|
|
|
|
{ language : Maybe String
|
2021-12-31 22:52:37 +03:00
|
|
|
, method : Request.Method
|
2021-12-16 07:10:54 +03:00
|
|
|
, queryParams : Dict String (List String)
|
|
|
|
, protocol : Url.Protocol
|
|
|
|
, allHeaders : Dict String String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-27 08:56:33 +03:00
|
|
|
|
|
|
|
--data : ServerRequest.IsAvailable -> RouteParams -> DataSource (PageServerResponse Data)
|
|
|
|
--data serverRequestKey routeParams =
|
|
|
|
-- let
|
|
|
|
-- serverReq : ServerRequest Request
|
|
|
|
-- serverReq =
|
|
|
|
-- ServerRequest.init
|
|
|
|
-- (\language method queryParams protocol allHeaders ->
|
|
|
|
-- { language = language
|
|
|
|
-- , method = method
|
|
|
|
-- , queryParams = queryParams |> QueryParams.toDict
|
|
|
|
-- , protocol = protocol
|
|
|
|
-- , allHeaders = allHeaders
|
|
|
|
-- }
|
|
|
|
-- )
|
|
|
|
-- |> ServerRequest.optionalHeader "accept-language"
|
|
|
|
-- |> ServerRequest.withMethod
|
|
|
|
-- |> ServerRequest.withQueryParams
|
|
|
|
-- |> ServerRequest.withProtocol
|
|
|
|
-- |> ServerRequest.withAllHeaders
|
|
|
|
-- in
|
|
|
|
-- serverReq
|
|
|
|
-- |> ServerRequest.toDataSource serverRequestKey
|
|
|
|
-- |> DataSource.andThen
|
|
|
|
-- (\req ->
|
|
|
|
-- case req.queryParams |> Dict.get "redirect" of
|
|
|
|
-- Just [ redirectTo ] ->
|
|
|
|
-- DataSource.succeed (PageServerResponse.ServerResponse (ServerResponse.temporaryRedirect redirectTo))
|
|
|
|
--
|
|
|
|
-- Just redirectParams ->
|
|
|
|
-- DataSource.succeed
|
|
|
|
-- (PageServerResponse.ServerResponse
|
|
|
|
-- (ServerResponse.stringBody
|
|
|
|
-- ("I got the wrong number of redirect query parameters (expected 1):\n"
|
|
|
|
-- ++ (redirectParams |> String.join "\n")
|
|
|
|
-- )
|
|
|
|
-- |> ServerResponse.withStatusCode 400
|
|
|
|
-- )
|
|
|
|
-- )
|
|
|
|
--
|
|
|
|
-- _ ->
|
|
|
|
-- req
|
|
|
|
-- |> DataSource.succeed
|
|
|
|
-- |> DataSource.map Data
|
|
|
|
-- |> DataSource.map PageServerResponse.RenderPage
|
|
|
|
|
|
|
|
|
2021-12-31 22:52:37 +03:00
|
|
|
data : RouteParams -> Request.Request (DataSource (PageServerResponse Data))
|
2021-12-27 08:56:33 +03:00
|
|
|
data routeParams =
|
|
|
|
Request.succeed ()
|
2021-12-31 22:14:23 +03:00
|
|
|
|> Request.map
|
2021-12-27 08:56:33 +03:00
|
|
|
(\() ->
|
2022-01-01 03:15:41 +03:00
|
|
|
PageServerResponse.ServerResponse (Server.Response.stringBody "Hello, this is a string")
|
2021-12-27 08:56:33 +03:00
|
|
|
|> DataSource.succeed
|
2021-12-21 22:58:12 +03:00
|
|
|
)
|
2021-12-16 07:10:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
head :
|
|
|
|
StaticPayload Data RouteParams
|
|
|
|
-> List Head.Tag
|
|
|
|
head static =
|
|
|
|
Seo.summary
|
|
|
|
{ canonicalUrlOverride = Nothing
|
|
|
|
, siteName = "elm-pages"
|
|
|
|
, image =
|
|
|
|
{ url = Pages.Url.external "TODO"
|
|
|
|
, alt = "elm-pages logo"
|
|
|
|
, dimensions = Nothing
|
|
|
|
, mimeType = Nothing
|
|
|
|
}
|
|
|
|
, description = "TODO"
|
|
|
|
, locale = Nothing
|
|
|
|
, title = "Time"
|
|
|
|
}
|
|
|
|
|> Seo.website
|
|
|
|
|
|
|
|
|
|
|
|
type alias Data =
|
|
|
|
{ request : Request
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Maybe PageUrl
|
|
|
|
-> Shared.Model
|
|
|
|
-> StaticPayload Data RouteParams
|
|
|
|
-> View Msg
|
|
|
|
view maybeUrl sharedModel static =
|
|
|
|
{ title = "Time"
|
|
|
|
, body =
|
|
|
|
[ Html.text (static.data.request |> Debug.toString)
|
|
|
|
]
|
|
|
|
}
|