Skip to content

Commit

Permalink
reads ClientBaseUrl from config
Browse files Browse the repository at this point in the history
  • Loading branch information
brase committed Mar 5, 2020
1 parent a6ec48e commit 03033fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Server/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ type AuthConfig = {
type Configuration =
{ Auth: AuthConfig
Url: string
ClientBaseUrl: string
Port: uint16
CorsUrls: string array }
3 changes: 2 additions & 1 deletion src/Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let appConfig =
Issuer = builder.["Auth:Issuer"] }
CorsUrls = builder.["CorsUrls"].Split([|';'|], System.StringSplitOptions.RemoveEmptyEntries)
Url = builder.["Url"]
ClientBaseUrl = builder.["ClientBaseUrl"]
Port = System.UInt16.Parse builder.["Port"] }

let eventStore = { LiteDb.Configuration.Empty with
Expand All @@ -50,7 +51,7 @@ let webApp appConfig = router {
forward "/api/users" (usersRouter eventStore db)
forward "/api/feeds" (feedsRouter eventStore)
forward "/api/subscriptions" (subscriptionsRouter eventStore)
forward "/smapi" (smapiRouter eventStore db)
forward "/smapi" (smapiRouter appConfig eventStore db)
}

let app = application {
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Smapi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ module Smapi =
Position = position }
storeEvent eventstore (fun _ -> streamId) ev

let processGetAppLink (db:Database.DatabaseConnection) s =
let processGetAppLink baseUrl (db:Database.DatabaseConnection) s =
let req = GetAppLinkRequest.Parse s
let houseHoldId = req.Body.GetAppLink.HouseholdId
let id = System.Guid.NewGuid()
Expand All @@ -249,7 +249,7 @@ module Smapi =

db.AddAuthRequest request

let loginFormUrl = (sprintf "http://localhost:8080/?linkcode=%A&householdid=%s" request.LinkCode request.HouseholdId)
let loginFormUrl = (sprintf "%s/?linkcode=%A&householdid=%s" baseUrl request.LinkCode request.HouseholdId)
let response = Smapi.Respond.getAppLinkResponse loginFormUrl (string request.LinkCode)
ok response

Expand Down
17 changes: 9 additions & 8 deletions src/Server/SmapiComposition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open Saturn
open FSharp.Control.Tasks.V2

open Castos
open Castos.Configuration
open Castos.Smapi
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
Expand Down Expand Up @@ -34,7 +35,7 @@ module SmapiCompositions =
| _ -> fail(sprintf "Method not implemented %s" m)
}

let internal processSmapiMethod eventStore db m =
let internal processSmapiMethod appConfig eventStore db m =
match m with
| GetMetadata (s, Some u) -> processGetMetadata eventStore u (GetMetadataRequest.Parse s)
| GetMetadata (_, None) -> fail "User not found"
Expand All @@ -48,12 +49,12 @@ module SmapiCompositions =
| ReportPlaySeconds (_, None) -> fail "user not found"
| ReportPlayStatus _ -> ok("")
| SetPlayedSeconds _ -> ok("")
| GetAppLink (s,u) -> processGetAppLink db s
| GetAppLink (s,u) -> processGetAppLink appConfig.ClientBaseUrl db s
| GetDeviceAuthToken (s,u) -> processGetDeviceAuthTokenRequest db s
| GetExtendedMetadata _ -> fail "not implemented"
| GetExtendedMetadataText _ -> fail "not implemented"

let internal smapiImp eventStore db (c:HttpContext) =
let internal smapiImp appConfig eventStore db (c:HttpContext) =
task {
let! result = getSmapiMethod db c
let log (ctx:HttpContext) (m:SmapiMethod) =
Expand All @@ -64,13 +65,13 @@ module SmapiCompositions =

return result
>>= log c
>>= (processSmapiMethod eventStore db)
>>= (processSmapiMethod appConfig eventStore db)
}

let internal processSmapiRequest eventStore db =
let internal processSmapiRequest appConfig eventStore db =
fun next ctx ->
task {
let! result = smapiImp eventStore db ctx
let! result = smapiImp appConfig eventStore db ctx
return! match result with
| Success (content) -> text content next ctx
| Failure (error) ->
Expand All @@ -79,6 +80,6 @@ module SmapiCompositions =
RequestErrors.BAD_REQUEST error next ctx
}

let smapiRouter eventStore db = router {
post "" (processSmapiRequest eventStore db)
let smapiRouter appConfig eventStore db = router {
post "" (processSmapiRequest appConfig eventStore db)
}

0 comments on commit 03033fb

Please sign in to comment.