diff --git a/examples/pokedex/src/Api.elm b/examples/pokedex/src/Api.elm index 4e4167e2..7c8e8255 100644 --- a/examples/pokedex/src/Api.elm +++ b/examples/pokedex/src/Api.elm @@ -10,8 +10,8 @@ import OptimizedDecoder as Decode import Route exposing (Route) import Secrets import Server.Request +import Server.Response import Server.SetCookie as SetCookie -import ServerResponse routes : @@ -40,16 +40,16 @@ jsonError = (\result -> case result of Ok firstName -> - ServerResponse.stringBody + Server.Response.stringBody ("Hello " ++ firstName) Err decodeError -> decodeError |> Json.Decode.errorToString - |> ServerResponse.stringBody - |> ServerResponse.withStatusCode 400 + |> Server.Response.stringBody + |> Server.Response.withStatusCode 400 ) - , Server.Request.succeed (ServerResponse.stringBody "Hello anonymous!") + , Server.Request.succeed (Server.Response.stringBody "Hello anonymous!") ] |> Server.Request.map DataSource.succeed ) @@ -76,7 +76,7 @@ greet = ] |> Server.Request.map (\firstName -> - ServerResponse.stringBody ("Hello " ++ firstName) + Server.Response.stringBody ("Hello " ++ firstName) |> DataSource.succeed ) ) @@ -95,7 +95,7 @@ fileLength = ) |> Server.Request.map (\file -> - ServerResponse.json + Server.Response.json (Json.Encode.object [ ( "File name: ", Json.Encode.string file.name ) , ( "Length", Json.Encode.int (String.length file.body) ) @@ -124,7 +124,7 @@ redirectRoute = ApiRoute.succeed (Server.Request.succeed (DataSource.succeed - (ServerResponse.temporaryRedirect "/") + (Server.Response.temporaryRedirect "/") ) ) |> ApiRoute.literal "api" @@ -146,7 +146,7 @@ noArgs = [ ( "repo", Json.Encode.string "elm-pages" ) , ( "stars", Json.Encode.int stars ) ] - |> ServerResponse.json + |> Server.Response.json ) ) ) @@ -187,8 +187,8 @@ logout = ApiRoute.succeed (Server.Request.succeed (DataSource.succeed - (ServerResponse.stringBody "You are logged out" - |> ServerResponse.withHeader "Set-Cookie" + (Server.Response.stringBody "You are logged out" + |> Server.Response.withHeader "Set-Cookie" (SetCookie.setCookie "username" "" |> SetCookie.httpOnly |> SetCookie.withPath "/" @@ -218,7 +218,7 @@ repoStars = [ ( "repo", Json.Encode.string repoName ) , ( "stars", Json.Encode.int stars ) ] - |> ServerResponse.json + |> Server.Response.json ) ) ) @@ -244,7 +244,7 @@ repoStars2 = [ ( "repo", Json.Encode.string repoName ) , ( "stars", Json.Encode.int stars ) ] - |> ServerResponse.json + |> Server.Response.json ) ) |> ApiRoute.literal "api2" diff --git a/examples/pokedex/src/Page/Greet.elm b/examples/pokedex/src/Page/Greet.elm index 40719b8b..f45cb0ba 100644 --- a/examples/pokedex/src/Page/Greet.elm +++ b/examples/pokedex/src/Page/Greet.elm @@ -12,7 +12,7 @@ import PageServerResponse exposing (PageServerResponse) import Pages.PageUrl exposing (PageUrl) import Pages.Url import Server.Request as Request -import ServerResponse +import Server.Response import Shared import Time import View exposing (View) @@ -62,7 +62,7 @@ data routeParams = ) , Request.succeed (DataSource.succeed - (PageServerResponse.ServerResponse (ServerResponse.temporaryRedirect "/login")) + (PageServerResponse.ServerResponse (Server.Response.temporaryRedirect "/login")) ) ] diff --git a/examples/pokedex/src/Page/Login.elm b/examples/pokedex/src/Page/Login.elm index b81e01a7..c28f4547 100644 --- a/examples/pokedex/src/Page/Login.elm +++ b/examples/pokedex/src/Page/Login.elm @@ -11,8 +11,8 @@ import PageServerResponse exposing (PageServerResponse) import Pages.PageUrl exposing (PageUrl) import Pages.Url import Server.Request as Request +import Server.Response import Server.SetCookie as SetCookie -import ServerResponse import Shared import View exposing (View) @@ -52,8 +52,8 @@ data routeParams = (\name -> PageServerResponse.ServerResponse ("/greet" - |> ServerResponse.temporaryRedirect - |> ServerResponse.withHeader "Set-Cookie" + |> Server.Response.temporaryRedirect + |> Server.Response.withHeader "Set-Cookie" (SetCookie.setCookie "username" name |> SetCookie.httpOnly |> SetCookie.withPath "/" diff --git a/examples/pokedex/src/Page/PokedexNumber_.elm b/examples/pokedex/src/Page/PokedexNumber_.elm index 501b790a..3040ab5c 100644 --- a/examples/pokedex/src/Page/PokedexNumber_.elm +++ b/examples/pokedex/src/Page/PokedexNumber_.elm @@ -12,7 +12,7 @@ import PageServerResponse exposing (PageServerResponse) import Pages.PageUrl exposing (PageUrl) import Pages.Url import Secrets -import ServerResponse +import Server.Response import Shared import View exposing (View) @@ -73,8 +73,8 @@ data { pokedexNumber } = notFoundResponse : String -> DataSource (PageServerResponse Data) notFoundResponse message = - ServerResponse.stringBody ("Not found.\n\n" ++ message) - |> ServerResponse.withStatusCode 404 + Server.Response.stringBody ("Not found.\n\n" ++ message) + |> Server.Response.withStatusCode 404 |> PageServerResponse.ServerResponse |> DataSource.succeed diff --git a/examples/pokedex/src/Page/Secret.elm b/examples/pokedex/src/Page/Secret.elm index ad0e27d3..88d17c0f 100644 --- a/examples/pokedex/src/Page/Secret.elm +++ b/examples/pokedex/src/Page/Secret.elm @@ -12,7 +12,7 @@ import Pages.PageUrl exposing (PageUrl) import Pages.Url import Route import Server.Request as Request -import ServerResponse +import Server.Response import Shared import View exposing (View) diff --git a/examples/pokedex/src/Page/Time.elm b/examples/pokedex/src/Page/Time.elm index 6bed8edd..09046418 100644 --- a/examples/pokedex/src/Page/Time.elm +++ b/examples/pokedex/src/Page/Time.elm @@ -10,7 +10,7 @@ import PageServerResponse exposing (PageServerResponse) import Pages.PageUrl exposing (PageUrl) import Pages.Url import Server.Request as Request -import ServerResponse +import Server.Response import Shared import Url import View exposing (View) @@ -98,7 +98,7 @@ data routeParams = Request.succeed () |> Request.map (\() -> - PageServerResponse.ServerResponse (ServerResponse.stringBody "Hello, this is a string") + PageServerResponse.ServerResponse (Server.Response.stringBody "Hello, this is a string") |> DataSource.succeed ) diff --git a/generator/src/Pages/Internal/Platform/Cli.elm b/generator/src/Pages/Internal/Platform/Cli.elm index 454f5d4a..24835374 100644 --- a/generator/src/Pages/Internal/Platform/Cli.elm +++ b/generator/src/Pages/Internal/Platform/Cli.elm @@ -37,7 +37,7 @@ import Pages.StaticHttpRequest as StaticHttpRequest import Path exposing (Path) import RenderRequest exposing (RenderRequest) import SecretsDict exposing (SecretsDict) -import ServerResponse +import Server.Response import Task import TerminalText as Terminal import Url @@ -826,7 +826,7 @@ nextStepToEffect site contentCache config model ( updatedStaticResponsesModel, n |> Effect.SendSinglePage False PageServerResponse.ServerResponse serverResponse -> - { body = serverResponse |> ServerResponse.toJson + { body = serverResponse |> Server.Response.toJson , staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v) , statusCode = 200 } @@ -997,7 +997,7 @@ sendSinglePageProgress site contentJson config model = |> Effect.SendSinglePage True PageServerResponse.ServerResponse serverResponse -> - { body = serverResponse |> ServerResponse.toJson + { body = serverResponse |> Server.Response.toJson , staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v) , statusCode = 200 } diff --git a/src/ApiRoute.elm b/src/ApiRoute.elm index 8ee12d29..5989634b 100644 --- a/src/ApiRoute.elm +++ b/src/ApiRoute.elm @@ -43,7 +43,7 @@ import Pattern exposing (Pattern) import Regex import Secrets import Server.Request -import ServerResponse +import Server.Response {-| -} @@ -84,7 +84,7 @@ stripTrailingSlash path = {-| -} -serverRender : ApiRouteBuilder (Server.Request.Request (DataSource ServerResponse.Response)) constructor -> ApiRoute Response +serverRender : ApiRouteBuilder (Server.Request.Request (DataSource Server.Response.Response)) constructor -> ApiRoute Response serverRender ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) = ApiRoute { regex = Regex.fromString ("^" ++ pattern ++ "$") |> Maybe.withDefault Regex.never @@ -108,17 +108,17 @@ serverRender ((ApiRouteBuilder patterns pattern _ toString constructor) as fullH Just (Err errors) -> errors |> Server.Request.errorsToString - |> ServerResponse.stringBody - |> ServerResponse.withStatusCode 400 + |> Server.Response.stringBody + |> Server.Response.withStatusCode 400 |> DataSource.succeed Nothing -> - ServerResponse.stringBody "No matching request handler" - |> ServerResponse.withStatusCode 400 + Server.Response.stringBody "No matching request handler" + |> Server.Response.withStatusCode 400 |> DataSource.succeed ) ) - |> Maybe.map (DataSource.map (ServerResponse.toJson >> Just)) + |> Maybe.map (DataSource.map (Server.Response.toJson >> Just)) |> Maybe.withDefault (DataSource.succeed Nothing) , buildTimeRoutes = DataSource.succeed [] @@ -138,7 +138,7 @@ serverRender ((ApiRouteBuilder patterns pattern _ toString constructor) as fullH {-| -} -preRenderWithFallback : (constructor -> DataSource (List (List String))) -> ApiRouteBuilder (DataSource ServerResponse.Response) constructor -> ApiRoute Response +preRenderWithFallback : (constructor -> DataSource (List (List String))) -> ApiRouteBuilder (DataSource Server.Response.Response) constructor -> ApiRoute Response preRenderWithFallback buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) = let buildTimeRoutes__ : DataSource (List String) @@ -155,7 +155,7 @@ preRenderWithFallback buildUrls ((ApiRouteBuilder patterns pattern _ toString co , matchesToResponse = \path -> Internal.ApiRoute.tryMatch path fullHandler - |> Maybe.map (DataSource.map (ServerResponse.toJson >> Just)) + |> Maybe.map (DataSource.map (Server.Response.toJson >> Just)) |> Maybe.withDefault (DataSource.succeed Nothing) , buildTimeRoutes = buildTimeRoutes__ diff --git a/src/PageServerResponse.elm b/src/PageServerResponse.elm index be0eeff4..08dc9817 100644 --- a/src/PageServerResponse.elm +++ b/src/PageServerResponse.elm @@ -6,7 +6,7 @@ module PageServerResponse exposing (map, PageServerResponse(..)) -} -import ServerResponse exposing (Response) +import Server.Response exposing (Response) {-| -} diff --git a/src/ServerResponse.elm b/src/Server/Response.elm similarity index 95% rename from src/ServerResponse.elm rename to src/Server/Response.elm index 00ce7361..f1d3eb2a 100644 --- a/src/ServerResponse.elm +++ b/src/Server/Response.elm @@ -1,4 +1,4 @@ -module ServerResponse exposing (Response, json, permanentRedirect, stringBody, success, temporaryRedirect, toJson, withHeader, withStatusCode) +module Server.Response exposing (Response, json, permanentRedirect, stringBody, success, temporaryRedirect, toJson, withHeader, withStatusCode) {-|