mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 21:29:55 +03:00
Rename ApiHandler -> ApiRoute.
This commit is contained in:
parent
b16f32c1fa
commit
6fab76ab96
@ -1,6 +1,6 @@
|
||||
module Site exposing (config)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import Cloudinary
|
||||
import DataSource exposing (DataSource)
|
||||
import DataSource.Http
|
||||
@ -28,9 +28,9 @@ config =
|
||||
}
|
||||
|
||||
|
||||
files : List (Maybe Route) -> List (ApiHandler.Done ApiHandler.Response)
|
||||
files : List (Maybe Route) -> List (ApiRoute.Done ApiRoute.Response)
|
||||
files allRoutes =
|
||||
[ ApiHandler.succeed
|
||||
[ ApiRoute.succeed
|
||||
(\userId ->
|
||||
DataSource.succeed
|
||||
{ body =
|
||||
@ -41,11 +41,11 @@ files allRoutes =
|
||||
|> Json.Encode.encode 2
|
||||
}
|
||||
)
|
||||
|> ApiHandler.literal "users"
|
||||
|> ApiHandler.slash
|
||||
|> ApiHandler.capture
|
||||
|> ApiHandler.literal ".json"
|
||||
|> ApiHandler.buildTimeRoutes
|
||||
|> ApiRoute.literal "users"
|
||||
|> ApiRoute.slash
|
||||
|> ApiRoute.capture
|
||||
|> ApiRoute.literal ".json"
|
||||
|> ApiRoute.buildTimeRoutes
|
||||
(\constructor ->
|
||||
DataSource.succeed
|
||||
[ constructor "1"
|
||||
@ -53,7 +53,7 @@ files allRoutes =
|
||||
, constructor "3"
|
||||
]
|
||||
)
|
||||
, ApiHandler.succeed
|
||||
, ApiRoute.succeed
|
||||
(\repoName ->
|
||||
DataSource.Http.get
|
||||
(Secrets.succeed ("https://api.github.com/repos/dillonkearns/" ++ repoName))
|
||||
@ -69,17 +69,17 @@ files allRoutes =
|
||||
}
|
||||
)
|
||||
)
|
||||
|> ApiHandler.literal "repo"
|
||||
|> ApiHandler.slash
|
||||
|> ApiHandler.capture
|
||||
|> ApiHandler.literal ".json"
|
||||
|> ApiHandler.buildTimeRoutes
|
||||
|> ApiRoute.literal "repo"
|
||||
|> ApiRoute.slash
|
||||
|> ApiRoute.capture
|
||||
|> ApiRoute.literal ".json"
|
||||
|> ApiRoute.buildTimeRoutes
|
||||
(\constructor ->
|
||||
DataSource.succeed
|
||||
[ constructor "elm-graphql"
|
||||
]
|
||||
)
|
||||
, ApiHandler.succeed
|
||||
, ApiRoute.succeed
|
||||
(DataSource.succeed
|
||||
{ body =
|
||||
allRoutes
|
||||
@ -93,8 +93,8 @@ files allRoutes =
|
||||
|> Sitemap.build { siteUrl = "https://elm-pages.com" }
|
||||
}
|
||||
)
|
||||
|> ApiHandler.literal "sitemap.xml"
|
||||
|> ApiHandler.singleRoute
|
||||
|> ApiRoute.literal "sitemap.xml"
|
||||
|> ApiRoute.singleRoute
|
||||
]
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module ApiHandler exposing (..)
|
||||
module ApiRoute exposing (..)
|
||||
|
||||
import DataSource exposing (DataSource)
|
||||
import Regex exposing (Regex)
|
@ -8,7 +8,7 @@ module Pages.Internal.Platform.Cli exposing
|
||||
, update
|
||||
)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import BuildError exposing (BuildError)
|
||||
import Codec
|
||||
import DataSource exposing (DataSource)
|
||||
@ -755,7 +755,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
case requestPayload of
|
||||
RenderRequest.Api ( path, apiHandler ) ->
|
||||
let
|
||||
thing : DataSource (Maybe ApiHandler.Response)
|
||||
thing : DataSource (Maybe ApiRoute.Response)
|
||||
thing =
|
||||
apiHandler.matchesToResponse path
|
||||
in
|
||||
@ -814,7 +814,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
case requestPayload of
|
||||
RenderRequest.Api ( path, apiHandler ) ->
|
||||
let
|
||||
thing : DataSource (Maybe ApiHandler.Response)
|
||||
thing : DataSource (Maybe ApiRoute.Response)
|
||||
thing =
|
||||
apiHandler.matchesToResponse path
|
||||
in
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), StaticResponses, error, init, nextStep, renderApiRequest, renderSingleRoute, update)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import BuildError exposing (BuildError)
|
||||
import DataSource exposing (DataSource)
|
||||
import DataSource.Http exposing (RequestDetails)
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Pages.SiteConfig exposing (SiteConfig)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import DataSource exposing (DataSource)
|
||||
import Head
|
||||
import Pages.Manifest
|
||||
@ -12,7 +12,7 @@ type alias SiteConfig route data =
|
||||
{ data : DataSource data
|
||||
, canonicalUrl : String
|
||||
, manifest : data -> Pages.Manifest.Config
|
||||
, apiRoutes : List (ApiHandler.Done ApiHandler.Response)
|
||||
, apiRoutes : List (ApiRoute.Done ApiRoute.Response)
|
||||
, head :
|
||||
data
|
||||
-> List Head.Tag
|
||||
|
@ -1,6 +1,6 @@
|
||||
module RenderRequest exposing (..)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import DataSource exposing (DataSource)
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode
|
||||
@ -12,7 +12,7 @@ import Url exposing (Url)
|
||||
|
||||
type RequestPayload route
|
||||
= Page { path : PagePath, frontmatter : route }
|
||||
| Api ( String, ApiHandler.Done ApiHandler.Response )
|
||||
| Api ( String, ApiRoute.Done ApiRoute.Response )
|
||||
| NotFound
|
||||
|
||||
|
||||
@ -106,9 +106,9 @@ requestPayloadDecoder config =
|
||||
route =
|
||||
pathToUrl path |> config.urlToRoute
|
||||
|
||||
apiRoute : Maybe (ApiHandler.Done ApiHandler.Response)
|
||||
apiRoute : Maybe (ApiRoute.Done ApiRoute.Response)
|
||||
apiRoute =
|
||||
ApiHandler.firstMatch (String.dropLeft 1 path)
|
||||
ApiRoute.firstMatch (String.dropLeft 1 path)
|
||||
(manifestHandler config
|
||||
:: site.apiRoutes
|
||||
)
|
||||
@ -136,9 +136,9 @@ requestPayloadDecoder config =
|
||||
|> Decode.field "payload"
|
||||
|
||||
|
||||
manifestHandler : ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData -> ApiHandler.Done ApiHandler.Response
|
||||
manifestHandler : ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData -> ApiRoute.Done ApiRoute.Response
|
||||
manifestHandler config =
|
||||
ApiHandler.succeed
|
||||
ApiRoute.succeed
|
||||
(config.getStaticRoutes
|
||||
|> DataSource.andThen
|
||||
(\resolvedRoutes ->
|
||||
@ -151,8 +151,8 @@ manifestHandler config =
|
||||
)
|
||||
)
|
||||
)
|
||||
|> ApiHandler.literal "manifest.json"
|
||||
|> ApiHandler.singleRoute
|
||||
|> ApiRoute.literal "manifest.json"
|
||||
|> ApiRoute.singleRoute
|
||||
|
||||
|
||||
manifestToFile : String -> Manifest.Config -> { body : String }
|
||||
|
@ -1,6 +1,6 @@
|
||||
module ApiHandlerTests exposing (..)
|
||||
module ApiRouteTests exposing (..)
|
||||
|
||||
import ApiHandler exposing (..)
|
||||
import ApiRoute exposing (..)
|
||||
import Expect
|
||||
import Test exposing (describe, only, test)
|
||||
|
@ -1,6 +1,6 @@
|
||||
module StaticHttpRequestsTests exposing (all)
|
||||
|
||||
import ApiHandler
|
||||
import ApiRoute
|
||||
import Codec
|
||||
import DataSource
|
||||
import DataSource.Http
|
||||
@ -693,7 +693,7 @@ Payload sent back invalid JSON""")
|
||||
[ test "initial requests are sent out" <|
|
||||
\() ->
|
||||
startLowLevel
|
||||
[ ApiHandler.succeed
|
||||
[ ApiRoute.succeed
|
||||
(DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
||||
(starDecoder
|
||||
|> Decode.map
|
||||
@ -703,8 +703,8 @@ Payload sent back invalid JSON""")
|
||||
)
|
||||
)
|
||||
)
|
||||
|> ApiHandler.literal "test.txt"
|
||||
|> ApiHandler.singleRoute
|
||||
|> ApiRoute.literal "test.txt"
|
||||
|> ApiRoute.singleRoute
|
||||
]
|
||||
(Ok ())
|
||||
[]
|
||||
@ -726,7 +726,7 @@ Payload sent back invalid JSON""")
|
||||
, test "it sends success port when no HTTP requests are needed because they're all cached" <|
|
||||
\() ->
|
||||
startLowLevel
|
||||
[ ApiHandler.succeed
|
||||
[ ApiRoute.succeed
|
||||
(DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages-starter")
|
||||
(starDecoder
|
||||
|> Decode.map
|
||||
@ -736,8 +736,8 @@ Payload sent back invalid JSON""")
|
||||
)
|
||||
)
|
||||
)
|
||||
|> ApiHandler.literal "test.txt"
|
||||
|> ApiHandler.singleRoute
|
||||
|> ApiRoute.literal "test.txt"
|
||||
|> ApiRoute.singleRoute
|
||||
]
|
||||
(Ok ())
|
||||
[ ( { url = "https://api.github.com/repos/dillonkearns/elm-pages"
|
||||
@ -798,7 +798,7 @@ startWithHttpCache =
|
||||
|
||||
|
||||
startLowLevel :
|
||||
List (ApiHandler.Done ApiHandler.Response)
|
||||
List (ApiRoute.Done ApiRoute.Response)
|
||||
-> Result String ()
|
||||
-> List ( Request.Request, String )
|
||||
-> List ( List String, DataSource.DataSource a )
|
||||
|
Loading…
Reference in New Issue
Block a user