Upgrade peach-web to use rocket 0.5 #15
No reviewers
Labels
No Label
bug
documentation
duplicate
enhancement
help wanted
invalid
maintenance
peach-lib
peach-network
peach-oled
peach-stats
peach-web
question
refactor
wontfix
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: PeachCloud/peach-workspace#15
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "rocket0.5"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Everything is now working, while running rocket 0.5. Lots of nice improvements in the new rocket, excited to use it.
Updating to 0.5, involved a few different syntax and API changes for interactions with rocket. The last two points (9 and 10) where not strictly necessary, but made sense to me to change while I was doing this (but ofc open to revising).
Here are bullets of the API changes that were required:
rocket_contrib::json moved into rocket::serde::json
rocket_contrib::template moved to
rocket_dyn_templates::Template;
flash.name() --> flash.kind()
flash.msg() --> flash.message()
rocket::request::{Form, FromForm}
--> rocket::form::{Form, FromForm}
uri! macro has new syntax
change RawStr to str& (based on what seems to be new Rocket convention)
Instead of NamedFile use new FileServer for serving static files
In order to enable (7), change rocket main.rs to use async via #[rocket::main] macro.
While doing this for (8) I deleted lib.rs, as initializing rocket in main.rs seemed simpler and more idiomatic from the projects I've looked at.
Rather than figure how to make web sockets work with the new async configuration, I removed the web socket code. As web sockets are currently not in use, I think its just generally a good practice to only keep code in the codebase which is being used. If we need it later, then we could re-add it, but open to other thoughts on this.
TODO:
for some reason it is failing with error
error[E0609]: no field
message
on typeJsonValue
... in this PR we completely got rid of the type JsonValue... so I have no idea where its even getting that from
... maybe caching something? I feel quite stumped by this small failing test...
Looks good overall; nice work! I've left some specific comments in the review for things which need to be address.
Good call removing the websockets code. That has been hanging around for ages 😅
Here's a fix for the json test:
@ -57,0 +57,4 @@
[dependencies.rocket_dyn_templates]
version = "0.1.0-rc.1"
features = ["handlebars", "tera"]
We can remove
handlerbars
here, since we're only using thetera
templating engine.@ -9,0 +121,4 @@
reset_password_form_endpoint, // JSON API
],
)
.mount("/", FileServer::from("static"))
The new
FileServer
API / workflow is really nice.@ -20,4 +20,4 @@
}
/// Test route: useful for ad hoc testing.
#[get("/api/v1/test")]
Can we make this route name more specific? One option is to stick with the established
ping
route convention and use:/api/v1/ping/dyndns
.I removed the test route,
-- fwiw the way I was using it was not as a test that needs to continue to exist,
but while building dyn_dns_updater,
a route that I could use to trigger the code I wanted to test.
Basically just a place where I can put arbitary code, and then call it by visiting that route.
But I will just temporarily re-add my lil test route when I want to use it for that, and it makes sense to not live in the codebase where it could cause confusion.
That makes sense to me. I can see the usefulness of a set of JSON
/api/v1/diagnosis/...
routes for these sorts of checks. It's really handy to have a programmatic and console-based way to query state.@ -23,3 +23,3 @@
#[get("/api/v1/test")]
pub fn test_route() -> Json<JsonResponse> {
pub fn test_route() -> Value {
let val = is_dns_updater_online().unwrap();
This is going to panic and crash the server if
is_dns_updater_online
returns an error. We should rather match on theResult
and return an appropriate JSONValue
if there's an error.@ -615,2 +613,3 @@
// decode ssid from url
let decoded_ssid = percent_decode(ssid.as_bytes()).decode_utf8().unwrap();
let decoded_ssid = ssid;
// let decoded_ssid = percent_decode(ssid.as_bytes()).decode_utf8().unwrap();
Was this commented-out line left in by mistake?
yup this was a mistake, good catch
@glyph thanks for the code review and test fix. Just pushed a change with the fixes
@notplants
Beautiful. I'm super happy to be up-to-date with the latest Rocket release.
Merge at your leisure 🙏