SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
708 stars 108 forks source link

How to route to an endpoint on the root #187

Closed mastoj closed 5 years ago

mastoj commented 5 years ago

This seems like a super simple stupid question, but those are allowed as well I guess.

I created a new app using the SAFE stack that I wanted to test out, but failed on thing that should be simple.

All I wanted to do was respond to a request to an endpoint at the root like /webhook. So I thought I will use my copy paste skills and changed the webApp part to:

let webApp = router {
    get "webhook" (fun next ctx ->
        task {
            let counter = {Value = 42}
            return! json counter next ctx
        })
    get "/api/init" (fun next ctx ->
        task {
            let counter = {Value = 42}
            return! json counter next ctx
        })

Now when I run the app /api/init works but /webhook doesn't. Any ideas why that is?

My app part look like this:

let app =
    application {
        url ("http://0.0.0.0:" + port.ToString() + "/")
        use_router webApp
        use_json_serializer(Thoth.Json.Giraffe.ThothSerializer())
        use_gzip
    }

run app

It is basically what you get from the SAFE template but I added my endpoint.

mastoj commented 5 years ago

I want to add that this is when I try to access the api directly and not through the webpack dev server that is provided through SAFE.

mastoj commented 5 years ago

I have no clue what's going on, but when I ran the app today it worked.