~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A site's page draws its frame at once, and finds visitors on a network of its own

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/site-network
crates/group-host/src/config.rs+6−0
@@ -73,6 +73,10 @@ pub struct Config {
/// `SITE_HANDLE_RESOLVER`: a service answering
/// `com.atproto.identity.resolveHandle`. Bluesky's unless set.
pub site_handle_resolver: String,
/// Where that page looks up the `did:plc` of whoever signs in,
/// `SITE_PLC_URL`: the directory as their browser reaches it, where
/// `PLC_URL` names one only the host reaches. `PLC_URL` unless set.
pub site_plc_url: String,
/// Where the host asks a group's own domain whether it reaches this
/// host, before serving the group's site there, `SITE_CHECK_AT`: a URL
/// asked in the domain's place, with the domain as its `Host` (a proxy
@@ -175,6 +179,7 @@ impl Config {
let site_shell = var("SITE_SHELL_DIR").map(std::path::PathBuf::from);
let site_handle_resolver =
var("SITE_HANDLE_RESOLVER").unwrap_or_else(|| "https://bsky.social".into());
let site_plc_url = var("SITE_PLC_URL").unwrap_or_else(|| plc_url.clone());
let site_check_at = var("SITE_CHECK_AT").map(|u| u.trim_end_matches('/').to_string());
Ok(Config {
port,
@@ -197,6 +202,7 @@ impl Config {
logs_keep,
site_shell,
site_handle_resolver,
site_plc_url,
site_check_at,
})
}
crates/group-host/src/sites.rs+5−1
@@ -698,7 +698,7 @@ fn shell(host: &Host, did: &str, handle: &str, site: &Value, path: &str) -> Resp
"writes": writes,
"aud": format!("{}#opensocial", host.config.service_did),
"handleResolver": host.config.site_handle_resolver,
"plc": host.config.plc_url,
"plc": host.config.site_plc_url,
"signUpAt": host.config.signup_pds,
"console": host.config.console_url,
"allowHttp": host.config.public_url.starts_with("http://"),
@@ -706,9 +706,13 @@ fn shell(host: &Host, did: &str, handle: &str, site: &Value, path: &str) -> Resp
// In a script element, `<` is the one thing that could end it early.
let config = config.to_string().replace('<', "\\u003c");
let frame = format!("/_site/{}", encoded(path));
// The frame sized before the page's script runs, so the browser never
// draws its own small bordered box first.
let page = format!(
"<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\">\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
<style>html,body{{margin:0;height:100%}}\
#os-page{{display:block;width:100%;height:100%;border:0}}</style>\
{head}</head><body>\
<iframe id=\"os-page\" title=\"{handle}\" data-src=\"{frame}\" \
sandbox=\"allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox\"></iframe>\
crates/group-host/tests/config.rs+12−0
@@ -135,6 +135,18 @@ fn someone_signs_up_at_bluesky_unless_told() {
assert!(refused.to_string().contains("SIGNUP_PDS"), "{refused}");
}
#[test]
fn a_sites_page_finds_its_visitor_in_the_directory_their_browser_reaches() {
assert_eq!(config(&[]).unwrap().site_plc_url, "https://plc.directory");
let own = config(&[("PLC_URL", "http://next-plc:3000")]).unwrap();
assert_eq!(own.site_plc_url, "http://next-plc:3000");
let told = [
("PLC_URL", "http://next-plc:3000"),
("SITE_PLC_URL", "https://plc.next.test"),
];
assert_eq!(config(&told).unwrap().site_plc_url, "https://plc.next.test");
}
#[test]
fn its_admins_and_how_many_lines_it_keeps() {
let c = config(&[]).unwrap();
crates/group-host/tests/sites.rs+8−0
@@ -492,6 +492,7 @@ async fn a_site_that_reads_is_served_in_the_page_that_holds_its_visitors_session
let vars = [
("SITE_SHELL_DIR", dir),
("SITE_HANDLE_RESOLVER", "https://pds.test"),
("SITE_PLC_URL", "https://plc.test"),
];
let h = start(&vars, false).await;
let (did, [alice, ..]) = group(&h).await;
@@ -535,6 +536,13 @@ async fn a_site_that_reads_is_served_in_the_page_that_holds_its_visitors_session
json!([format!("{NS}.getGroup"), format!("{NS}.listMembers")])
);
assert_eq!(config["handleResolver"], "https://pds.test");
assert_eq!(config["plc"], "https://plc.test");
// Its frame sized before the page's script runs.
assert!(
shell
.body
.contains("#os-page{display:block;width:100%;height:100%;border:0}")
);
// A page the site has no file for is missing there too, its preview
// the notFound page's; a site with neither, the group's handle.
let lost = page(&h, "/rides/42").await;
deploy/docker-compose.yml+4−0
@@ -38,6 +38,10 @@ services:
PROVISIONING_CLIENTS: ${GROUP_HOST_PROVISIONING_CLIENTS:-}
PDS_CRAWLERS: ${GROUP_HOST_CRAWLERS:-}
SIGNUP_PDS: ${GROUP_HOST_SIGNUP_PDS:-https://bsky.social}
# Where a site's page, in the visitor's browser, looks up their handle
# and their did:plc: a directory only the host reaches is no use there.
SITE_HANDLE_RESOLVER: ${GROUP_HOST_SITE_HANDLE_RESOLVER:-https://bsky.social}
SITE_PLC_URL: ${GROUP_HOST_SITE_PLC_URL:-${GROUP_HOST_PLC_URL:-https://plc.directory}}
BLOB_UPLOAD_LIMIT: ${GROUP_HOST_BLOB_UPLOAD_LIMIT:-52428800}
RUST_LOG: ${GROUP_HOST_LOG:-info}
HOST_ADMINS: ${GROUP_HOST_ADMINS:-}
docs/design/sites.md+5−3
@@ -383,9 +383,11 @@ has a handle field, which `searchActors` at the address fills with
suggestions as you type, and "Create one", which makes an account at
`SIGNUP_PDS`. A page may suggest a handle, but it can't send anyone
anywhere. The visitor sees where they're signing in, types or confirms
the handle, and enters their password only at their own PDS. The host
resolves the typed handle through `SITE_HANDLE_RESOLVER`. Back from
approving, the visitor lands signed in on the page they started from.
the handle, and enters their password only at their own PDS. The page
resolves the typed handle through `SITE_HANDLE_RESOLVER`, and the DID
that names through `SITE_PLC_URL`, both from the visitor's browser
([configuration](../reference/config.md)). Back from approving, the
visitor lands signed in on the page they started from.
The host's page at the address isn't sandboxed, since it must keep a
session. It's the host's own code, the same for every group. The site's
docs/reference/config.md+2−0
@@ -27,6 +27,8 @@ item of spaces and a trailing `/`.
| `ACTOR_SEARCH` | where `searchActors` looks up a handle as someone types it. `plc` reads the handles in `PLC_URL`'s own export a page at a time and keeps them a minute. Otherwise it's the URL of a service answering `tech.waow.typeahead.searchActors` | typeahead.waow.tech's when `PLC_URL` is `https://plc.directory`, else `plc` |
| `SIGNUP_PDS` | the PDS where someone without an account makes one, from the console's "Create one", through its authorization server's sign-up (`prompt=create`). It drops a trailing `/` | `https://bsky.social` |
| `SITE_SHELL_DIR` | where the built page around a site that names `reads` lives, with its `shell.js` (`web/build-shell`, which `npm run build` in `web/` makes, and the image sets `/app/build-shell`) | none, so such a site's pages load no script |
| `SITE_HANDLE_RESOLVER` | where the page around a site looks up the handle a visitor types to sign in, from their browser: a service answering `com.atproto.identity.resolveHandle`, such as their network's PDS | `https://bsky.social` |
| `SITE_PLC_URL` | where that page looks up the visitor's `did:plc`, from their browser. Set it when `PLC_URL` names a directory only the host reaches, such as one on its own network | `PLC_URL` |
| `SITE_CHECK_AT` | where the host checks that a group's own domain reaches this host before it serves the group's site there. It asks this URL in the domain's place, with the domain as its `Host`. Use it when a host can't reach its own public addresses | the domain itself, over https |
| `PDS_CRAWLERS` | relays the host tells of news with `requestCrawl`, comma-separated, a trailing `/` dropped. It tells them at most every 20 minutes, and the first time after a start | none |
| `RUST_LOG` | what it logs, as `tracing-subscriber`'s filter reads it. Lines are JSON, written to stdout and kept in `logs.sqlite` for its operators | `info` |
docs/deploying.md+2−0
@@ -58,6 +58,8 @@ Compose reads these and passes each to the host under the name the host knows:
| `GROUP_HOST_PROVISIONING_CLIENTS` | `PROVISIONING_CLIENTS` | none |
| `GROUP_HOST_CRAWLERS` | `PDS_CRAWLERS` | none |
| `GROUP_HOST_SIGNUP_PDS` | `SIGNUP_PDS` | `https://bsky.social` |
| `GROUP_HOST_SITE_HANDLE_RESOLVER` | `SITE_HANDLE_RESOLVER` | `https://bsky.social` |
| `GROUP_HOST_SITE_PLC_URL` | `SITE_PLC_URL` | `GROUP_HOST_PLC_URL`'s |
| `GROUP_HOST_BLOB_UPLOAD_LIMIT` | host `BLOB_UPLOAD_LIMIT` and console `BODY_SIZE_LIMIT` | `52428800` |
| `GROUP_HOST_LOG` | `RUST_LOG` | `info` |
| `GROUP_HOST_ADMINS` | `HOST_ADMINS`, the operators who read its logs and stats | none |
web/shell/shell.ts+1−2
@@ -57,8 +57,7 @@ const style = document.createElement('style');
style.textContent = `${consoleStyles}
html:root:not([data-theme='light']) { color-scheme: normal; }
html, body { margin: 0; padding: 0; height: 100%; background: none; }
@media (prefers-color-scheme: dark) { #${SIGN_IN} { color-scheme: dark; } }
#os-page { display: block; width: 100%; height: 100%; border: 0; }`;
@media (prefers-color-scheme: dark) { #${SIGN_IN} { color-scheme: dark; } }`;
document.head.append(style);
const client = BrowserOAuthClient.load({