alpmestan / servant

Moved to http://github.com/haskell-servant
50 stars 1 forks source link

Static file #30

Closed soenkehahn closed 9 years ago

soenkehahn commented 10 years ago

I created this PR just to have a place for discussion.

soenkehahn commented 10 years ago

I'm not sure I like this approach. I didn't think that every static file and its endpoint should be represented in the type of the API. For static files we can just use Raw and some static file wai application, like https://hackage.haskell.org/package/wai-app-static. Yes, we do get a less precise representation of the API in its type, but maybe that's exactly what we want.

The common use case, I think, is that you have a directory of static files (html, css, js, images, etc.) and want that to be mounted to a certain endpoint. I don't want to be forced to adapt the API type every time I decide to add a static file. Also, Servant.API.File doesn't allow to host directories. Additionally, the static files will most likely be fetched by a browser, so we don't even make use of the HasClient instance.

In conclusion, I have the slight feeling we would be misusing the typed web API idea to implement a static file server. We should just accept that serving static files cannot be easily "typed" (in the servant sense).

Of course my approach (using something like wai-app-static through Raw) is still perfectly possible if this gets merged. Maybe you can elaborate on your use case?

alpmestan commented 10 years ago

I wasn't done, I had that Dir/StaticDir patch in the works. It's now committed, please take a look and let me know what you think. It's the combinator responsible for "mounting" a whole directory under a certain endpoint in a webapp.