Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from rocket.rs to axum #51

Closed
80 tasks done
secana opened this issue Oct 3, 2023 · 3 comments
Closed
80 tasks done

Migrate from rocket.rs to axum #51

secana opened this issue Oct 3, 2023 · 3 comments
Labels
help wanted Extra attention is needed implementation Change an implementation details without adding new functionality
Milestone

Comments

@secana
Copy link
Contributor

secana commented Oct 3, 2023

What/Why

Kellnr was started more than three years ago. Rocket.rs was one of the most promising web frameworks at that time. Unfortunatly the development stopped. Axum emerged as a new popular framework with it's roots in the tokio ecosystem, which makes it a perfect fit for Kellnr, as tokio is already heavily used.

To Do

Kellnr uses rocket.rs for routing, authentication and serving static files. All of this has to be migrated. The list below gives an overview of what has to be done.

The behavior should not change to make the migration as smooth as possible. For nearly all APIs multiple corresponding tests exist.

Contribute

The branch migrate-to-axum is used. If you intend to help with the migration, fork the project and use this branch as the base for your work. Please check the migrated APIs below, such that it is clear what is still missing and work is not done multiple times.

Root - UI

The root serves mostly UI related APIs.

API

  • ui::kellnr_version
  • ui::crates
  • registry::kellnr_api::me
  • ui::search
  • ui::statistic
  • web_ui::settings::settings
  • ui::crates_data
  • ui::cratesio_data
  • ui::delete
  • ui::build_rustdoc

Tests

  • ui::kellnr_version
  • ui::crates
  • registry::kellnr_api::me
  • ui::search
  • ui::statistic
  • web_ui::settings::settings
  • ui::crates_data
  • ui::cratesio_data
  • ui::delete
  • ui::build_rustdoc

Static File Server

This route serve static file content, e.g. the user interface for Kellnr.

API

  • "/" -> serves "./static"

User

The user API manages all things related to Kellnr users, for example creating a user or adding a authentication token.

API

  • user::login
  • user::logout
  • user::change_pwd
  • user::add
  • user::delete
  • user::delete_forbidden (still needed?)
  • user::reset_pwd
  • user::add_token
  • user::delete_token
  • user::list_token
  • user::list_users
  • user::login_state

Tests

  • user::login
  • user::logout
  • user::change_pwd
  • user::add
  • user::delete
  • user::delete_forbidden (still needed?)
  • user::reset_pwd
  • user::add_token
  • user::delete_token
  • user::list_token
  • user::list_users
  • user::login_state

Crates

The API for the crates are implemted under /api/v1/crates. This is the heart of Kellnr and allows cargo to push and pull crates.

API

  • index::kellnr_prefetch_api::prefetch_kellnr
  • index::kellnr_prefetch_api::prefetch_len2_kellnr
  • index::kellnr_prefetch_api::config_kellnr
  • registry::kellnr_api::download
  • registry::kellnr_api::publish
  • registry::kellnr_api::yank
  • registry::kellnr_api::unyank
  • registry::kellnr_api::search
  • registry::kellnr_api::list_owners
  • registry::kellnr_api::add_owner
  • registry::kellnr_api::remove_owner

Tests

  • index::kellnr_prefetch_api::prefetch_kellnr
  • index::kellnr_prefetch_api::prefetch_len2_kellnr
  • index::kellnr_prefetch_api::config_kellnr
  • registry::kellnr_api::download
  • registry::kellnr_api::publish
  • registry::kellnr_api::yank
  • registry::kellnr_api::unyank
  • registry::kellnr_api::search
  • registry::kellnr_api::list_owners
  • registry::kellnr_api::add_owner
  • registry::kellnr_api::remove_owner

Crates.io

Kellnr can proxy and cache crates.io, as such it dublicates the crates API from above for crates.io

API

  • index::cratesio_prefetch_api::prefetch_cratesio
  • index::cratesio_prefetch_api::prefetch_len2_cratesio
  • index::cratesio_prefetch_api::config_cratesio
  • registry::cratesio_api::download
  • registry::cratesio_api::search
  • ui::delete_cratesio_index

Tests

  • index::cratesio_prefetch_api::prefetch_cratesio
  • index::cratesio_prefetch_api::prefetch_len2_cratesio
  • index::cratesio_prefetch_api::config_cratesio
  • registry::cratesio_api::download
  • registry::cratesio_api::search
  • ui::delete_cratesio_index

Not Found

Forward all not found pages to the vue.js router.

  • "not found" -> "/static/index.html" -> The vue.js router will take over from here
@secana secana added help wanted Extra attention is needed implementation Change an implementation details without adding new functionality labels Oct 3, 2023
@jplatte
Copy link
Contributor

jplatte commented Oct 3, 2023

In case it's not known already, ServeDir from tower-http is the most common solution for serving static files from disk.

There is a known issue for automatic redirects (/static/foo to /static/foo/ if foo is a directory in the ServeDir disk directory), if enabled and ServeDir is nested using nest_service.

It sounds like you want anything that's not a (known?) API route to go to static file serving though? In that case the ServeDir should be added as a .fallback_service() on the router, and the issue linked above is irrelevant. There's just one extra thing to note: you need to set an explicit fallback on the api router if you don't want unknown /api routes to go to ServeDir (since the fallback is otherwise inherited by the nested API router).

secana added a commit that referenced this issue Oct 15, 2023
secana added a commit that referenced this issue Oct 15, 2023
@secana secana added this to the 5.0.0 milestone Oct 15, 2023
secana added a commit that referenced this issue Oct 15, 2023
@secana
Copy link
Contributor Author

secana commented Oct 31, 2023

All APIs are ported and all test work with axum.

Next:

  • Remove all rocket references
  • Port logging settings from rocket to axum
  • Test all functionality manually for cases that miss a test

@secana
Copy link
Contributor Author

secana commented Nov 1, 2023

All test run successfully. Port to axum finished.

@secana secana closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed implementation Change an implementation details without adding new functionality
Projects
None yet
Development

No branches or pull requests

2 participants