Wide range of web improvements #70
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#70
Loading…
Reference in New Issue
No description provided.
Delete Branch "web_improvements"
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?
In the name of expedience, I'm breaking my personal rule about not making large PRs.
Changes
This PR introduces a number of changes / improvements / removals which were prompted by my experiment to convert peach-web to using
rouille
andmaud
.noscript
template snippetsnafu
with a custom error implementationpeach-stats
andpeach-network
src/router.rs
WLAN_IFACE
andAP_IFACE
struct
s (replaced withtera::Context
type)back
,title
and flash message datastruct
s and builders to a dedicated directorysrc/routes
files much quieter and cleared in my experience)Tests are passing (
DISABLE_ROCKET_AUTH=true PEACH_STANDALONE_MODE=false cargo test
).There will undoubtedly be some bugs that I haven't caught but I think this PR gets us to a solid point of being able to focus purely on standalone mode features and polish in preparation for release.
I'm very happy that this PR effectively reduces the codebase by 500 lines.
CC: @notplants (I don't expect you to do a thorough review but hopefully the summary above serves to update you on the important changes).
cool to have trimmed down the codebase so much!
I particularly like this change
reduces code and makes things more ergonomic to work with in the future
also glad to see snafu removed
here are a few comments, none blocking. could merge this PR and address these separately as inspired.
the first comment is probably the smallest and most utilitarian change.
the second I think could be a code improvement but is a larger change.
the third is just sharing my opinion, but I'm happy that you've rearranged the code into a structure that you find more appealing, since it doesn't make a big difference to me.
you can slightly restructure build_minimal_rocket so that it takes in a
Rocket<Build>
and returns aRocket<Build>
and thus can be called by build_complete_rocket, and then avoid duplicating routes (duplicate code in general means more typing + more chance of introducing bugs through discrepancies between the duplication).I would also consider to change the names to mount_peachpub_routes, and mount_all_peachcloud_routes (which calls mount_peachpub_routes), and/or to have a build function which calls the correct mount function based on what environment it is, and then additionally do whatever other configuration is needed.
my suggestion is a reiteration of One Config To Rule Them All, which I don't mean configs instead of env vars, what I mean is one way of handling configurations, so that for any configuration (whether peach_standalone_mode or something else) you know there is one system and one config file which handles all of them, and you dont have to arbitrarily remember which configs are handled in which ways.
if we want the ability to set env var, instead of as a a value in config.yml, I would change to using figment to handle all configurations and use a hierarchy (env > config)
and then I would have PEACH_STANDALONE_MODE as one config thats handled in the same way as all the others.
figment looks pretty easy to setup a hierarchy like this (https://docs.rs/figment/0.10.6/figment/). and then we would just need to change all the functions in config_manager to get values from figment instead of with the home-made yaml reading.
one question I've been thinking about is how this would interact with rocket's own config system (which we need to use for the rocket authentication env). I wouldn't just use rocket's env system for everything, because we also want to have access to configurations for processes running outside of a rocket context (e.g. peach-config). I have a feeling, from some reading, that there might be a way to set the file rocket reads its configuration from during the build phase, and then set this file to be /var/lib/peachcloud/config.toml , that way this config file can be read by rocket, and also read by figment from processes that are not running rocket.
but all that said, we can also keep this multiple configs now, and it could be a separate issue at some point if desired to replace config_manager with figment and then make these changes at that point.
personally my preference is still:
... have many small route files, even one file per route, so the code for each route is all together in one file along with the context, forms and data types for that route
I think having long files with many context and routes is hard to read and causes the feeling of noisiness, but small files its helpful to see everything that interacts all together, and then its super easy to make new routes, you just copy a file to a new location and edit everything in place.
but its also not my hill to die on (quoting clgbh). this also seems organized and readable to me, and now since routes and contexts are divided into multiple files based on function, instead of a single file for each, they will not get unmanageably long.
If looking deeper into using figment instead of the current config_manager,
some other things to consider:
54359924f6
toed6da528a2
^ I was trying to add a commit that would just remove
static/js/*
from Cargo.toml
so that cargo-deb would compile without complaining that static/js doesn't exist anymore,
but while adding this change,
it also added some changes to Cargo.lock (due to the automatic cargo fmt running as a git pre-commit hook), so I had to temporarily turn that off, then force push, so it would just send the commit with the js line removed
ceed34cb49
to4d2a3771b8
@notplants
Thanks for taking a look and sharing your thoughts. I'm feeling a bit low on energy today so I'll keep my response brief:
Deduplication sounds good to me. I'll do this in a separate PR as it requires some careful thought to avoid routing conflicts (for example, the Scuttlebutt status view needs to be mounted at
/status
for PeachPub and at/status/scuttlebutt
for PeachCloud).I've copied your config-related comments over to the config issue #37. I used the simplest possible solution in this PR to avoid getting stuck in the mud. I'll respond more fully in the issue.
I'm happy to revisit the separation in the future. Individual files per route still seems a bit extreme to me but our application isn't too big so maybe it would feel good once I tried it.
could consider mounting routes at the same URL in both cases, /status/scuttlebutt, to keep the code simpler.
cool
I really don't mind the way you have it setup so whatever you prefer. I think I have a general preference for functional groupings (things that interact) instead of optical groupings (things that look similar).
imo I'm also not sure the size of the app effects this pattern. If you have many routes, then you would continue to subdivide them into functional groupings in folders.
reflecting more on it, I think a key organizational preference of mine is small files. Not necessarily one route per file (but could be if they are complicated routes), but that whenever a file starts to get big, it could be a chance to come up with groupings and divide it. I'm trying to remember what the other rust reference I found was besides Plume where they had many small routes files, kind of bummed I can't find it or remember it right now
aw right, delta was the project that had a nice implementation of one route per file https://github.com/revoltchat/delta/tree/master/src/routes
but yea seriously, less than not my hill to die, I think the current organization is also fine.