Open sordina opened 6 years ago
I can't speak to Scotty, but in Yesod we have the ability to defer handling to a WAI application. That would seem to me a better approach than a middleware. That said, I'm not opposed to adding functionality here if you think it would be useful in general.
I found ifRequest
seems to take us almost all the way there. All that's needed is a constMiddleware
that turns an application into middleware which is almost trivial.
I'll have a go at implementing and see what you think!
Routes in scotty
are literally just Middleware
, where the addroute
function just adds the checking for the correct path and method and then runs the handler with the request. So I think it should be easy enough to add a raw application into a scotty
app. (cf. addroute
, addRoute
, route
)
Not sure if this should be an issue, just close if not appropriate!
I'd been wanting to use wai-app-static in a Scotty app (or any wai app really) but found it hard to compose with other applications since it is an Application in its own right. This can be remedied by wrapping it to turn it into a middleware like so:
https://github.com/sordina/wai-app-static-file-embed-middleware/blob/master/src/Main.hs#L20
I can't decide if such functionality should be in wai in general, or in libraries such as wai-app-static.
Thoughts?