tower-http icon indicating copy to clipboard operation
tower-http copied to clipboard

It's unclear how to hook ServeDir in

Open alper opened this issue 3 years ago • 4 comments

I couldn't really figure out how to hook ServeDir in looking at this documentation: https://docs.rs/tower-http/latest/tower_http/services/struct.ServeDir.html

Putting it in my router as a new route() —just like all the other routes— did not work but when I switched it to nest() like the example, it did. I don't really understand why though.

Debugging this was also not very successful.

alper avatar Mar 05 '22 10:03 alper

I'm now trying to vary the base path and running into difficulties again.

Would it be possible to return a custom error page in a DEBUG mode?

alper avatar Mar 05 '22 10:03 alper

tower-http doesn't know anything about axum so I don't think its appropriate for its docs to treat axum with special attention. axum has docs here and here that shows how to use ServeDir. Searching for ServeDir in the axum repo does find the examples. Not sure how to improve that.

Would it be possible to return a custom error page in a DEBUG mode?

I don't think a custom error page is appropriate but we could add some TRACE logging to help people debug issues. What specifically would have helped you debug your issues?

davidpdrsn avatar Mar 05 '22 10:03 davidpdrsn

I think a trace of the path being asked for (after being cut up etc.) and then a trace of the file system path being tried would be very helpful here.

Also it would be nice to add the nest() way of hooking this in to the documentation.

alper avatar Mar 05 '22 11:03 alper

I think a trace of the path being asked for (after being cut up etc.) and then a trace of the file system path being tried would be very helpful here.

Sounds good 👍 Do you wanna attempt making a PR?

Also it would be nice to add the nest() way of hooking this in to the documentation.

Like I mentioned, I don't think its appropriate for tower-https docs to include axum specific examples.

davidpdrsn avatar Mar 05 '22 11:03 davidpdrsn

I'll close this for now. You're welcome to submit a PR that adds more logging to ServeDir.

davidpdrsn avatar Dec 02 '22 12:12 davidpdrsn