Closed sheganinans closed 5 years ago
I don't know the difference atm, but I think I am using "route" without the "sub" successfully. Can you try that? Otherwise I can look up the exact code I use tomorrow.
@0x53A I tried something like that but it didn't work.
Exactly what I want to be able to do is to have the user browse to www.webpage.com/example
and have the index page for IexampleApi
load and then have them browse to www.webpage.com/other
and have the index for IOtherApi
load.
That would likely require two separate clients talking to the same server. Could be simpler to just have two separate servers..
I guess I need to add to the webpack config
Hello @sheganinans, it should work if you add the subroute prefix in the route builder implementation and not inside Giraffe subsroute like this:
module Route =
let builder prefix typeName methodName =
sprintf "/%s/api/%s/%s" prefix typeName methodName
Then when setting up the HttpHandler you can add your prefix:
// Server
let exampleRouter =
Remoting.createApi()
|> Remoting.withRouteBuilder (Route.builder "example")
|> Remoting.fromValue Api.exampleApi
|> Remoting.buildHttpHandler
let webApp =
choose [ exampleRouter ]
// Client
let api : IExampleApi =
Remoting.createApi()
|> Remoting.withRouteBuilder (Route.builder "example")
|> Remoting.buildProxy<IExampleApi>
Can you give it a try?
@Zaid-Ajaj Ok, thats seems right. Now the question is, if I wanted to add a second router, with its own index page, that would require quite a bit more work?
@sheganinans Yes it is a bit more work, follow webpack's config of setting up multiple entry points. I will close this issue since it is not specific to this library
Using the SAFE template, so in
Shared.fs
I have:On the Server:
On the Client:
The problem I have is that I would like to put
exampleRouter
behind a subroute, something likelocalhost:8080/example/api/.../
I'm doing this so that I can have some
otherRouter
alongsideexampleRouter
, such as:However everything I've tried so far ends me up with a 404