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

feature: custom domains using Fairings #596

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

feature: custom domains using Fairings #596

wants to merge 48 commits into from

Conversation

igalic
Copy link
Contributor

@igalic igalic commented May 24, 2019

This Pull Request addresses #94; replaces #447;
We start by adding custom_domain to the blogs 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 the Host 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

  • PostgreSQL Migrations
  • SQLite Migrations
  • Custom time to represent domain (Host)
  • Expand Blog (and NewBlog)
  • Update /blog/new and /blog/edit to add custom domain field
  • Cache custom domains on startup and on insert/update.
  • /custom_domains/ mount-point which handles these domains
  • implement routes for
    • blog details
    • post details
    • blog activity_details
    • search
    • routes necessary for federation??
  • implement redirect for the "legacy" routes for the above
    • blog details
    • post details
    • blog activity_details ??
    • search
  • Update URLs in templates
  • Update URLs in base template for search
  • Check correct domain setup
  • Test: Federation
  • Some explanations (in the UI, next to the setting and in the docs)

@igalic igalic requested review from elegaanz and trinity-1686a and removed request for elegaanz May 24, 2019 13:52
@codecov
Copy link

codecov bot commented May 24, 2019

Codecov Report

Merging #596 into master will increase coverage by 3.54%.
The diff coverage is 32.14%.

@@            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

src/main.rs Outdated Show resolved Hide resolved
plume-models/src/blogs.rs Outdated Show resolved Hide resolved
plume-models/src/blogs.rs Outdated Show resolved Hide resolved
plume-models/src/blogs.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 28, 2019

Codecov Report

Merging #596 into master will decrease coverage by 0.47%.
The diff coverage is 16.73%.

@@            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

@igalic
Copy link
Contributor Author

igalic commented May 29, 2019

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 ap_url, inbox_url and outbox_url on blog creation (or update) and i would have to modify the templates to use the correct URL scheme.
Alternatively we create an URL builder which we resolves the correct URLs.

Currently, there are a lot of places in which URLs are built ad-hoc.
In some cases, this is okay, because it's just pointing to a rocket route, but in many cases it feels painful, because we're doing manual labour that a function could remove.

the compute_box() function for instance, feels quite pointless. There is no computation happening at all, just concatenation! compute_box() itself calls ap_url() which only prepends https://

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.

@trinity-1686a
Copy link
Contributor

To do this, I would have to adapt the URLs ap_url, inbox_url and outbox_url on blog creation (or update) and i would have to modify the templates to use the correct URL scheme.

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

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.

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)

@igalic
Copy link
Contributor Author

igalic commented May 30, 2019

okay, so, at this point, i'm about as done as i can be, without touching the templates or refactoring the URL building.

Copy link
Member

@elegaanz elegaanz left a 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.

plume-models/src/blogs.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
src/routes/posts.rs Outdated Show resolved Hide resolved
src/routes/posts.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@igalic igalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation?

src/routes/blogs.rs Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
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.
src/routes/blogs.rs Outdated Show resolved Hide resolved
this doesn't work (yet?), because i don't know how to store something
mutable in State<>
Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

src/routes/blogs.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
src/main.rs Outdated
@@ -196,6 +197,7 @@ Then try to restart Plume
}
});

let mut valid_domains: HashMap<&str, Instant> = HashMap::new();
Copy link
Contributor

@trinity-1686a trinity-1686a Aug 15, 2019

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

Copy link
Contributor Author

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

Copy link
Contributor

@trinity-1686a trinity-1686a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

src/routes/blogs.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
src/routes/blogs.rs Outdated Show resolved Hide resolved
@@ -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(""),
Copy link
Member

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).

Copy link
Contributor Author

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?

@marek-lach marek-lach added the C: Feature This is a new feature label Aug 30, 2019
@elegaanz elegaanz changed the base branch from master to main July 5, 2020 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Feature This is a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants