activitypub-federation-rust/examples
Colin Atkinson d9f1a4414f
Fix regex error when actix-web feature not enabled (#56)
* Fix formatting for nightly rustfmt

https://github.com/LemmyNet/lemmy/issues/3467

* Fix regex error when actix-web feature not enabled

If the crate is built with only the axum feature, compiling the
webfinger account regex will fail with an error "Unicode-aware case
insensitivity matching is not available..." because of the missing
unicode-case feature. This doesn't happen if actix is installed because
it pulls in the regex crate with all features (via [actix-router][0]).

The failure can be demonstrated by reverting this commit's change to
Cargo.toml and running:

    cargo test --no-default-features --features=axum --doc extract_webfinger_name

Resolve this by adding the unicode-case feature to the regex dependency.

[0]: 0e8ed50e3a/actix-router/Cargo.toml (L25)
2023-07-03 15:05:18 +02:00
..
live_federation Fix regex error when actix-web feature not enabled (#56) 2023-07-03 15:05:18 +02:00
local_federation Fix regex error when actix-web feature not enabled (#56) 2023-07-03 15:05:18 +02:00
README.md live federation example 2023-03-08 22:16:43 +01:00

Examples

Local Federation

Creates two instances which run on localhost and federate with each other. This setup is ideal for quick development and well as automated tests. In this case both instances run in the same process and are controlled from the main function.

In case of Lemmy we are using the same setup for continuous integration tests, only that multiple instances are started with a bash script as different threads, and controlled over the API.

Use one of the following commands to run the example with the specified web framework:

cargo run --example local_federation axum

cargo run --example local_federation actix-web

Live Federation

A minimal application which can be deployed on a server and federate with other platforms such as Mastodon. For this it needs run at the root of a (sub)domain which is available over HTTPS. Edit main.rs to configure the server domain and your Fediverse handle.

Setup instructions:

  • Deploy the project to a server. For this you can clone the git repository on the server and execute cargo run --example live_federation. Alternatively run cargo build --example live_federation and copy the binary at target/debug/examples/live_federation to the server.
  • Create a TLS certificate. With Let's Encrypt certbot you can use a command like certbot certonly --nginx -d 'example.com' -m '*your-email@domain.com*' (replace with your actual domain and email).
  • Setup a reverse proxy which handles TLS and passes requests to the example project. With nginx you can use the following basic config, again using your actual domain:
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    location / {
        proxy_pass "http://localhost:8003";
        proxy_set_header Host $host;
    }
}
  • Test with curl -H 'Accept: application/activity+json' https://example.com/alison | jq and curl -H 'Accept: application/activity+json' "https://example.com/.well-known/webfinger?resource=acct:alison@example.com" | jq that the server is setup correctly and serving correct responses.
  • Login to a Fediverse platform like Mastodon, and search for @alison@example.com, with the actual domain and username from your main.rs. If you send a message, it will automatically send a response.