Rethink paths
Currently, we have a router that handles parsing the paths.
It supports multiple modes:
- Browsing a single crate's sources (
/browse/<crate>/<version>/<path>) - Diffing a crate against different versions (
/<crate>/<old>/<new>/<path>) - Diffing across crates (
/<old-crate>/<old-version>/<new-crate>/<new-version>/<path>)
The reason the parsing works is because a valid version can never be a valid crate name (because crate names can't start with numbers and can't contain periods). However, it would be fragile (I need to review it manually, or maybe use proptest to see if there are any routes that could be interpreted in multiple ways).
One current issue is that there is a default redirect. If you open up diff.rs/serde, this is what happens:
- default versions inserted: redirect to
/serde/previous/latest - versions resolved: redirect to
/serde/1.0.209/1.0.210/ - default file: redirect to
/serde/1.0.209/1.0.210/Cargo.toml
But this does not work if you want to view the about crate, because we have a page at /about. So as we add more (internal) pages, we will alias this crate redirection.
Maybe a more structured routing approach could be better. For example:
/about(internal pages)/diff/<crate>/<old>/<new/files/<path>/diff/<old-crate>/<old-version>/<new-crate>/<new-version>/files/<path>/view/<crate>/<version>/files/<path>
Adding the prefix /diff and /view lets us make sure these paths can never clash with our internal pages. Adding the files prefix before showing files allows us to render other data on crates (like a summary page, or something like that) in the future.
I think we should think about this and figure out what a sane approach could be. And also keep in mind to not break backwards-compatibility for old links.