Make it possible to test the federation locally
And explain how to do it in the README
This commit is contained in:
parent
5f43f783b6
commit
ac1a111d7b
22
README.md
22
README.md
|
@ -39,3 +39,25 @@ cargo run
|
||||||
You'll need Rust nightly.
|
You'll need Rust nightly.
|
||||||
|
|
||||||
Once the app started, try to visit [localhost:8000](http://localhost:8000).
|
Once the app started, try to visit [localhost:8000](http://localhost:8000).
|
||||||
|
|
||||||
|
To configure the instance (needed before you can do anything else),
|
||||||
|
go on [/configire](http://localhost:8000/configure).
|
||||||
|
|
||||||
|
## Testing the federation
|
||||||
|
|
||||||
|
To test the federation, you'll need to setup another database (see "Setup the database"),
|
||||||
|
also owned by the "plume" user, but with a different name. Then, you'll need to run the
|
||||||
|
migrations for this database too.
|
||||||
|
|
||||||
|
```
|
||||||
|
diesel migration run --database-url postgres://plume:plume@localhost/my_other_plume_db
|
||||||
|
```
|
||||||
|
|
||||||
|
To run this other instance, you'll need to give two environment variables:
|
||||||
|
|
||||||
|
- `ROCKET_PORT`, the port on which your app will run
|
||||||
|
- `DB_NAME`, the name of the database you just created
|
||||||
|
|
||||||
|
```
|
||||||
|
ROCKET_PORT=3033 DB_NAME=my_other_plume_db cargo run
|
||||||
|
```
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
use activity_pub::{activity_pub, ActivityPub, context};
|
use BASE_URL;
|
||||||
|
use activity_pub::{activity_pub, ActivityPub, context, ap_url};
|
||||||
use activity_pub::activity::Activity;
|
use activity_pub::activity::Activity;
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ pub trait Actor: Sized {
|
||||||
"summary": "",
|
"summary": "",
|
||||||
"url": self.compute_id(conn),
|
"url": self.compute_id(conn),
|
||||||
"endpoints": {
|
"endpoints": {
|
||||||
"sharedInbox": "https://plu.me/inbox"
|
"sharedInbox": ap_url(format!("{}/inbox", BASE_URL.as_str()))
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -58,12 +59,12 @@ pub trait Actor: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
fn compute_id(&self, conn: &PgConnection) -> String {
|
||||||
format!(
|
ap_url(format!(
|
||||||
"https://{instance}/{prefix}/{user}",
|
"{instance}/{prefix}/{user}",
|
||||||
instance = self.get_instance(conn).public_domain,
|
instance = self.get_instance(conn).public_domain,
|
||||||
prefix = Self::get_box_prefix(),
|
prefix = Self::get_box_prefix(),
|
||||||
user = self.get_actor_id()
|
user = self.get_actor_id()
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_to_inbox(&self, conn: &PgConnection, act: Activity) {
|
fn send_to_inbox(&self, conn: &PgConnection, act: Activity) {
|
||||||
|
|
|
@ -16,6 +16,17 @@ pub type ActivityPub = Content<Json>;
|
||||||
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
|
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
|
||||||
pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public";
|
pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public";
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
pub fn ap_url(url: String) -> String {
|
||||||
|
format!("http://{}", url)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
pub fn ap_url(url: String) -> String {
|
||||||
|
format!("https://{}", url)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn context() -> serde_json::Value {
|
pub fn context() -> serde_json::Value {
|
||||||
json!([
|
json!([
|
||||||
CONTEXT_URL,
|
CONTEXT_URL,
|
||||||
|
|
|
@ -4,6 +4,8 @@ use reqwest::header::{Accept, qitem};
|
||||||
use reqwest::mime::Mime;
|
use reqwest::mime::Mime;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
|
use activity_pub::ap_url;
|
||||||
|
|
||||||
pub trait Webfinger {
|
pub trait Webfinger {
|
||||||
fn webfinger_subject(&self, conn: &PgConnection) -> String;
|
fn webfinger_subject(&self, conn: &PgConnection) -> String;
|
||||||
fn webfinger_aliases(&self, conn: &PgConnection) -> Vec<String>;
|
fn webfinger_aliases(&self, conn: &PgConnection) -> Vec<String>;
|
||||||
|
@ -26,7 +28,7 @@ pub trait Webfinger {
|
||||||
|
|
||||||
pub fn resolve(acct: String) -> Result<String, String> {
|
pub fn resolve(acct: String) -> Result<String, String> {
|
||||||
let instance = acct.split("@").last().unwrap();
|
let instance = acct.split("@").last().unwrap();
|
||||||
let url = format!("https://{}/.well-known/webfinger?resource=acct:{}", instance, acct);
|
let url = ap_url(format!("{}/.well-known/webfinger?resource=acct:{}", instance, acct));
|
||||||
Client::new()
|
Client::new()
|
||||||
.get(&url[..])
|
.get(&url[..])
|
||||||
.header(Accept(vec![qitem("application/jrd+json".parse::<Mime>().unwrap())]))
|
.header(Accept(vec![qitem("application/jrd+json".parse::<Mime>().unwrap())]))
|
||||||
|
|
|
@ -40,7 +40,7 @@ lazy_static! {
|
||||||
.unwrap_or(format!("127.0.0.1:{}", env::var("ROCKET_PORT").unwrap_or(String::from("8000"))));
|
.unwrap_or(format!("127.0.0.1:{}", env::var("ROCKET_PORT").unwrap_or(String::from("8000"))));
|
||||||
|
|
||||||
pub static ref DB_URL: String = env::var("DB_URL")
|
pub static ref DB_URL: String = env::var("DB_URL")
|
||||||
.unwrap_or(format!("DATABASE_URL=postgres://plume:plume@localhost/{}", env::var("DB_TABLE").unwrap_or(String::from("plume"))));
|
.unwrap_or(format!("postgres://plume:plume@localhost/{}", env::var("DB_NAME").unwrap_or(String::from("plume"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
type PgPool = Pool<ConnectionManager<PgConnection>>;
|
type PgPool = Pool<ConnectionManager<PgConnection>>;
|
||||||
|
|
|
@ -2,6 +2,7 @@ use rocket::http::ContentType;
|
||||||
use rocket::response::Content;
|
use rocket::response::Content;
|
||||||
|
|
||||||
use BASE_URL;
|
use BASE_URL;
|
||||||
|
use activity_pub::ap_url;
|
||||||
use activity_pub::webfinger::Webfinger;
|
use activity_pub::webfinger::Webfinger;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::Blog;
|
use models::blogs::Blog;
|
||||||
|
@ -12,9 +13,9 @@ fn host_meta() -> String {
|
||||||
format!(r#"
|
format!(r#"
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Link rel="lrdd" type="application/xrd+xml" template="https://{domain}/.well-known/webfinger?resource={{uri}}"/>
|
<Link rel="lrdd" type="application/xrd+xml" template="{url}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
"#, domain = BASE_URL.as_str())
|
"#, url = ap_url(format!("{domain}/.well-known/webfinger?resource={{uri}}", domain = BASE_URL.as_str())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
|
|
Loading…
Reference in New Issue