Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwarding api with saturn returns 404 #198

Open
Freymaurer opened this issue Nov 25, 2020 · 2 comments
Open

Forwarding api with saturn returns 404 #198

Freymaurer opened this issue Nov 25, 2020 · 2 comments

Comments

@Freymaurer
Copy link

Freymaurer commented Nov 25, 2020

This is a continuation of issue #197. After the DateTime issue was fixed i updated from Fable.Remoting.Giraffe 4.10 to 4.13 and noticed how all apis managed by Fable.Remoting returned with 404. I looked into the issue you linked by @Arshia001 and did some testing.

As background information, i am using the SAFE stack with saturn and this problem occurs during development (with webpack).

let testWebApp =
    Remoting.createApi()
    |> Remoting.withRouteBuilder Route.builder
    |> Remoting.fromValue testApi
    |> Remoting.withDiagnosticsLogger(printfn "%A")
    |> Remoting.withErrorHandler(
        (fun x y -> Propagate (sprintf "[SERVER SIDE ERROR]: %A @ %A" x y))
    )
    |> Remoting.buildHttpHandler

let testRouter = 
    /// does not work
    forward "/api/ITestAPI" (fun next ctx ->
        testWebApp next ctx
    ) 
   /// does work
   forward "" (fun next ctx ->
        testWebApp next ctx
   )

let app = application {
    url "http://localhost:5000/"
    use_router testRouter
    memory_cache
    use_static "public"
    use_gzip
    logging (fun (builder: ILoggingBuilder) -> builder.SetMinimumLevel(LogLevel.Warning) |> ignore)
}

Of course both variants are not active at the same time, i only wrote it like this for easier comparison. As you can see if i don't specify the api url path for forwarding it works.

For the sake of completeness, my apis were written and worked as follows before the update:

let mainApiController = router {
    forward "/ITestAPI" (fun next ctx ->
        testWebApp next ctx
    )
}
let topLevelRouter = router {
    forward "/api" mainApiController

let app = application {
    url "http://localhost:5000/"
    //force_ssl
    use_router topLevelRouter
    memory_cache
    use_static "public"
    use_gzip
    logging (fun (builder: ILoggingBuilder) -> builder.SetMinimumLevel(LogLevel.Warning) |> ignore)
}

I hope this helps to find the problem. IIf you need any more information i will be happy to help. Thanks for all the hard work!

@Zaid-Ajaj
Copy link
Owner

Thanks a lot for the issue report @Freymaurer, this is very helpful 😄 I will investigate

@kaashyapan
Copy link

kaashyapan commented Nov 7, 2021

I think I ran into this issue when trying to add a plug to the pipeline and having 2 remoting api interfaces.
Is there any advice on how to workaround ?

This works

        choose [ 
            route "/api/health" >=> healthHandler
            application2Handler 
            application1Handler 
        ]

This doesnt

        router {
            pipe_through apiKeyPipe
            get "/api/health" healthHandler
            forward "/api/app1" (fun next ctx -> application1Handler next ctx)
            forward "/api" (fun next ctx -> application2Handler next ctx)
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants