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
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6bcc4f0
add custom_domain (default to NULL) to schema
igalic May 22, 2019
92bbeeb
add Host(String) wrapper type
igalic May 24, 2019
65ae51b
implement Host more completely by doing less
igalic May 25, 2019
351c01f
list custom_domains
igalic May 25, 2019
3a4c2f2
create & attach an AdHoc Fairing for dealing with Custom Domains
igalic May 26, 2019
2746e08
appease clippy
igalic May 26, 2019
e6747de
cache custom_domains list
igalic May 26, 2019
b09b51c
normalize URLs before setting them
igalic May 27, 2019
f94b0c7
move impl closer to mother struct
igalic May 27, 2019
0645f7e
CustomDomainFairing must not match /static/ and /api/
igalic May 27, 2019
468e663
Add custom_details and custom_activity_details as first routes
igalic May 27, 2019
1c34ac3
replace if / else with ok_or()
igalic May 27, 2019
8e6b1ab
simplify retrieval in find_by_host()
igalic May 28, 2019
a0aef50
extract common routing code into private "_guts()" functions
igalic May 28, 2019
6253adf
simplify / unify error handling
igalic May 28, 2019
92fbd17
extend 404 handler to handle all the requests our custom_ routes dont
igalic May 28, 2019
8e7f789
Allow searching from custom_domain
igalic May 30, 2019
9cee38a
add url to Blog, this seems useful.
igalic May 31, 2019
cc0df4e
redirect blog urls to custom_domain if it exists
igalic Jun 14, 2019
fe110b5
fix issues pointed out by @BaptisteGelez in review
igalic Jun 15, 2019
f73fba5
custom_domainify posts::details
igalic Jul 10, 2019
203da23
follow up on @fdb-hiroshima & @BaptisteGelez review
igalic Jul 12, 2019
7139119
add url! macro for custom domain path uri creation
trinity-1686a Jul 14, 2019
f635dcf
move custom_ route functions into a custom namespace
igalic Jul 14, 2019
cdc919e
allow more syntaxes for url
trinity-1686a Jul 14, 2019
6cd8bd8
fix syntax: we're now down to type errors
igalic Jul 21, 2019
c5f6b88
make url! work better
trinity-1686a Jul 22, 2019
b172a80
finally fix url!
trinity-1686a Jul 22, 2019
2dedcdb
start modifying /blogs/new to add custom_domain to the form
igalic Jul 30, 2019
fdc7da0
Strings have to be cloned
elegaanz Jul 31, 2019
6027012
fix clippy warning
igalic Jul 31, 2019
da6757c
Basic domain validation
elegaanz Jul 31, 2019
ff0c82e
review by @fdb-hiroshima
igalic Aug 1, 2019
bf1673d
start exploring some ideas for domain validation
igalic Aug 14, 2019
ed30284
implement domain validation using rocket::State
igalic Aug 15, 2019
444a467
correctly mutex-lock and modify valid_domains
igalic Aug 19, 2019
6072351
one step closer to validating custom domains!
igalic Aug 19, 2019
5e46922
validate custom domain!
igalic Aug 19, 2019
38ece9b
do not panic if reqwest does not work
igalic Aug 20, 2019
f67ce93
fix getter router for domain_validation!
igalic Aug 20, 2019
df47cdd
also mount domain_validation into /custom_domains/
igalic Aug 20, 2019
064dd79
Allow editing blogs with custom_domain
igalic Aug 20, 2019
1694698
use Custom status code
igalic Aug 20, 2019
768f126
use Status::* as @fdb-hiroshima suggested
igalic Aug 20, 2019
df7adaf
when building links, skip both, /custom_domain/ and <custom_domain>
igalic Aug 20, 2019
f395c10
fix mount point for blog post routing function
igalic Aug 20, 2019
d242e6d
restore df7adaf0e067802daf3e83935cf9140fb15ca17b ← after fixing mount…
igalic Aug 20, 2019
3c4abcf
Allow updating of custom_domain
igalic Aug 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/routes/blogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rocket::{
};
use rocket_i18n::I18n;
use std::sync::Mutex;
use std::time::Instant;
use std::time::{Duration, Instant};
use std::{borrow::Cow, collections::HashMap};
use validator::{Validate, ValidationError, ValidationErrors};

Expand Down Expand Up @@ -179,8 +179,24 @@ fn valid_slug(title: &str) -> Result<(), ValidationError> {
}
}

fn valid_domain(domain: &str, valid_domains: State<Mutex<HashMap<String, Instant>>>) -> bool {
let mutex = valid_domains.inner().lock();
let mut validation_map = mutex.unwrap();

validation_map.insert(
utils::random_hex(),
Instant::now().checked_add(Duration::new(60, 0)).unwrap(),
);

true
igalic marked this conversation as resolved.
Show resolved Hide resolved
}

#[post("/blogs/new", data = "<form>")]
pub fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> RespondOrRedirect {
pub fn create(
form: LenientForm<NewBlogForm>,
rockets: PlumeRocket,
valid_domains: State<Mutex<HashMap<String, Instant>>>,
) -> RespondOrRedirect {
let slug = utils::make_actor_id(&form.title);
let conn = &*rockets.conn;
let intl = &rockets.intl.catalog;
Expand All @@ -189,7 +205,7 @@ pub fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> RespondOr
let (custom_domain, dns_ok) = if form.custom_domain.is_empty() {
(None, true)
} else {
let dns_check = true; // TODO
let dns_check = valid_domain(&form.custom_domain.clone(), valid_domains);
(Some(Host::new(form.custom_domain.clone())), dns_check)
};

Expand Down