Skip to content

Commit

Permalink
Application-CE: Throw on multipe *_router
Browse files Browse the repository at this point in the history
Adds a check when `use_router` is called twice, or `use_router` after
`no_router` or the other way around, and fail directly.
This is to prohibit setting two routers, which does not have any effect…
only the last router is used, which might be confusing.

Fixes SaturnFramework#323.
  • Loading branch information
ChrSteinert committed May 31, 2024
1 parent 1c27657 commit 7da37c7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Saturn/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ module Application =
///Defines top-level router used for the application
[<CustomOperation("use_router")>]
member __.Router(state, handler) =
{state with Router = Some handler}
match state.NoRouter, state.Router with
| false, None -> {state with Router = Some handler}
| true, _ -> failwith "Cannot add a router, after `no_router` was set!"
| _, Some _ -> failwith "Cannot add a second router!"

///Defines top-level endpoint router used for the application
[<CustomOperation("use_endpoint_router")>]
Expand All @@ -236,7 +239,9 @@ module Application =
///Disable warning message about lack of `router` definition. Should be used for channels-only or gRPC applications.
[<CustomOperation("no_router")>]
member __.NoRouter(state) =
{state with NoRouter = true}
match state.Router with
| Some _ -> failwith "Cannot set `no_router` after a router with `use_router` has been set!"
| _ -> {state with NoRouter = true}

///Disables any configuration of webhost. Could be used for generic `IHostBuilder` applications not using Kestrel/IIS
[<CustomOperation("no_webhost")>]
Expand Down

0 comments on commit 7da37c7

Please sign in to comment.