-
Notifications
You must be signed in to change notification settings - Fork 135
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
feature: custom domains using Fairings #596
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #596 +/- ##
==========================================
+ Coverage 30.96% 34.51% +3.54%
==========================================
Files 66 67 +1
Lines 7822 7916 +94
Branches 1881 1894 +13
==========================================
+ Hits 2422 2732 +310
+ Misses 4700 4421 -279
- Partials 700 763 +63 |
Codecov Report
@@ Coverage Diff @@
## master #596 +/- ##
==========================================
- Coverage 35.33% 34.86% -0.48%
==========================================
Files 68 68
Lines 7915 8149 +234
Branches 1894 1946 +52
==========================================
+ Hits 2797 2841 +44
- Misses 4341 4529 +188
- Partials 777 779 +2 |
so: I'm a bit at an impasse or crossroads with this patch, and it all kinda depends on how far i wanna push it. For now, i've added a 404 handler, which redirects to the main-site, which means, actually, everything works now 😹 (by redirecting to the main site) We could present the complete illusion that this custom domain, is the real domain, and all there is is this one blog. To do this, I would have to adapt the URLs Currently, there are a lot of places in which URLs are built ad-hoc. the I would like to propose a Universal URL builder… or rather, a plumey-versal URL builder, which can be used from any part of plume's code to construct a correct plume URL. |
I think it would be best to still handle most of (~all) ap stuff on the main domain, having an id (as requested in #296) for the activity that goes to the main domain, with a redirect to the correct path when queried (so either the main domain with better name than the id, or custom one when applicable). Also with some webfinger trick it should be possible to have more than one handle for a blog, so there could be the one from the main domain, that shouldn't change because it would break a lot of federation stuff, and an alias based on the custom domain. All this would be in the spirit of not breaking things if the custom domain for a blog changes
that would be a good idea for everything that need to integrate the domain in addition to a path. It could be a small macro that call the rocket one, and prepand the domain name, either from local_instance if none is given, or the one given (which would be a custom domain) |
okay, so, at this point, i'm about as done as i can be, without touching the templates or refactoring the URL building. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it a try, and it seems to work quite well so far! I left a few comment about the code itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validation?
we can use this to handle rocket Requests (from_request) but we still have to figure out how to automatically assign the type to custom_domain: Optional<Host>, and public_domain: Host.
we now use DieselNewType and Shrinkwrap to automatically derive all the things we need.
thanks a lot to @fdb-hiroshima and @BaptisteGelez for helping with the code.
this rewrites the URL to /custom_domain/<url> (we have no route handlers for this path yet) Lots of help from @fdb-hiroshima & @BaptisteGelez in dealing with the borrow checker — thank you 💜️
follow #572 and cache the list of custom domains.
thanks, again, @fdb-hiroshima for helping with this code, when i got stuck in lifetime-hecc.
there is still some issue with `None`, and an error making no sense at some place
also please a bit clippy
Co-Authored-By: fdb-hiroshima <[email protected]>
The actual DNS check still needs to be written
Co-Authored-By: fdb-hiroshima <[email protected]>
this doesn't work (yet?), because i don't know how to store something mutable in State<>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
src/main.rs
Outdated
@@ -196,6 +197,7 @@ Then try to restart Plume | |||
} | |||
}); | |||
|
|||
let mut valid_domains: HashMap<&str, Instant> = HashMap::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be in favor of using the newtype design pattern for this, so that it make more sense what it is, even at the type level.
I don't know where are the &str coming from, but you might want to use String instead, or you'll have some difficulties with lifetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aye. i haven't gotten that far yet, because i haven't implemented the other side of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
thanks to @fdb-hiroshima for the review
n.b.: no validation yet
thanks, @fdb-hiroshima Co-Authored-By: fdb-hiroshima <[email protected]>
@@ -351,6 +351,10 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { | |||
.clone() | |||
.expect("blogs::edit: User was None while it shouldn't"); | |||
let medias = Media::for_user(conn, user.id).expect("Couldn't list media"); | |||
let custom_domain = match blog.custom_domain { | |||
Some(ref c) => c.to_string(), | |||
_ => String::from(""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a quite personal opinion, but I think blog.custom_domain.map(ToString::to_string).unwrap_or_default()
is more explicit (but, yes, it is only my opinion, maybe it is not).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another question might be: why were you able to use Option<String>
for theme
in EditForm
but i have to use String
here?
This Pull Request addresses #94; replaces #447;
We start by adding
custom_domain
to theblogs
table; and a custom type Host(String)A blog with
custom_domain
has special routes with higher priority, but administrative routes will remain on the instance host.We'll use
Fairings
to extract theHost
header, to then specially route them.Domain administration is left to the user (and/or admin)
(but we might be able to provide a check on whether it's already correctly configured)
TODO
Host
)Blog
(andNewBlog
)/blog/new
and/blog/edit
to add custom domain field/custom_domains/
mount-point which handles these domains