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

A dev world's group sites open in a browser, at their addresses

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:dev/site-names
crates/group-host/src/sites.rs+1−1
@@ -259,7 +259,7 @@ impl Host {
let record = self.store.record(did, SITE, "self");
let Some(record) = record.map_err(XrpcError::internal)? else {
if asking.path.is_empty() {
let page = format!("{}/g/{handle}", self.config.public_url);
let page = format!("{}/g/{handle}", self.config.console_url);
return Ok(moved(&page, StatusCode::FOUND));
}
return Ok(plain(StatusCode::NOT_FOUND, "no site here"));
crates/group-host/tests/sites.rs+3−2
@@ -167,13 +167,14 @@ async fn a_site_is_published_and_served_sandboxed() {
#[tokio::test]
async fn a_site_without_its_pages_answers_plainly() {
let h = start(&[], false).await;
let h = start(&[("CONSOLE_URL", "https://console.test")], false).await;
let (did, [alice, ..]) = group(&h).await;
// Its page in the console, wherever the console is.
let console = page(&h, "/").await;
assert_eq!(console.status, 302);
assert_eq!(
console.header("location"),
format!("https://host.test/g/{RIDERS}")
format!("https://console.test/g/{RIDERS}")
);
assert_eq!(page(&h, "/about").await.status, 404);
crates/opensocial/src/lib.rs+1−1
@@ -57,7 +57,7 @@ role
site
site publish <group> <dir> [--fallback <path>] [--not-found <path>]
publish the files under <dir> as the group's website, at its
handle, in place of the one there
address, in place of the one there
site delete <group> take the group's website down
member
member list <group> [--q <text>] [--limit <n>] [--cursor <cursor>]
docs/development.md+6−0
@@ -24,6 +24,12 @@ account signs in as its handle (`alice.test`, `bob.test`,
codes the PDS emails are read, and how to run the command against it. ctrl-c stops it all, and each start is empty
again.
Its groups are named under `groups.localtest.me`, as
`riders.groups.localtest.me`, so a group's address opens in a browser:
a site published with `site publish` is at https://riders.groups.localtest.me,
sandboxed as it is when deployed, and a group with none sends `/` to its
page in the console.
Signing in to the console takes https at a name: the host is the
console's OAuth client, and a PDS fetches a client's metadata only so.
portless (a harness package) serves it: its proxy on port 443 sends
harness/dev.mjs+25−7
@@ -2,7 +2,8 @@
// look at: the reference PDS with alice, bob and harbor on it, the host, the
// console at https://group-host.localtest.me, served by the dev server so a
// change to it shows at once, a group of alice's, and one of bob's that has
// invited her.
// invited her. Groups are named under groups.localtest.me, so a group's
// address, where its site is, opens in a browser too.
// Stops on ctrl-c, and forgets everything: the PDS, the directory and the
// host start empty each time.
//
@@ -21,6 +22,10 @@ import { root, start } from './world.mjs';
const NAME = 'group-host';
const DOMAIN = 'localtest.me';
/// What groups are named under, by an alias of this name: its wildcard
/// sends each group's address to the host, as a deployment's does.
const GROUPS = 'groups';
const groups = `${GROUPS}.${DOMAIN}`;
const portless = join(root, 'harness/node_modules/.bin/portless');
const state = process.env.PORTLESS_STATE_DIR ?? join(homedir(), '.portless');
@@ -51,8 +56,18 @@ const w = await start({
accounts: ['alice', 'bob', 'harbor'],
front,
pdsEnv: { NODE_EXTRA_CA_CERTS: join(state, 'ca.pem') },
live: true
live: true,
handleDomain: `.${groups}`
});
execFileSync(portless, ['alias', GROUPS, new URL(w.host).port, '--force'], { stdio: 'ignore' });
/// Takes both names back from portless.
const unalias = () => {
for (const name of [NAME, GROUPS])
try {
execFileSync(portless, ['alias', '--remove', name], { stdio: 'ignore' });
} catch {}
};
// Hikers, bob's, inviting alice: an invite waiting for her when she signs
// in, as the header, its menu and the home page mark one.
@@ -72,24 +87,25 @@ const [alice, bob] = ['alice.test', 'bob.test'].map((h) =>
w.net.accounts.find((a) => a.handle === h)
);
try {
as(bob, 'group', 'create', 'hikers.groups.test', '--display-name', 'Hikers');
as(bob, 'group', 'create', `hikers.${groups}`, '--display-name', 'Hikers');
as(
bob,
'invite',
'send',
'hikers.groups.test',
`hikers.${groups}`,
alice.handle,
'--message',
'Walk with us on Sundays.'
);
} catch (e) {
unalias();
w.stop();
throw e;
}
const stop = () => {
try {
execFileSync(portless, ['alias', '--remove', NAME], { stdio: 'ignore' });
unalias();
} finally {
w.stop();
process.exit(0);
@@ -108,12 +124,14 @@ The directory ${w.net.plc}
Sign in as any of them, with their password at the PDS's own page:
${people}
alice runs Riders (riders.groups.test). bob runs Hikers (hikers.groups.test),
alice runs Riders (riders.${groups}). bob runs Hikers (hikers.${groups}),
which has invited alice: her invite waits on the home page. harbor is an account of its own, to
move here from ${w.base}/move; the code its server emails is at
${w.net.mail}?to=harbor@test.com
A group's site is at its address, once published: https://riders.${groups}
The command, as alice:
OPENSOCIAL_HOST=${w.host} PDS_URL=${w.net.pds} OPENSOCIAL_AS=alice.test OPENSOCIAL_PASSWORD=password just opensocial group show riders.groups.test
OPENSOCIAL_HOST=${w.host} PDS_URL=${w.net.pds} OPENSOCIAL_AS=alice.test OPENSOCIAL_PASSWORD=password just opensocial group show riders.${groups}
ctrl-c stops it all.`);
harness/world.mjs+11−4
@@ -105,8 +105,15 @@ export const serviceAuth = async (pds, account, aud, lxm) => {
/// served at the port `front` is given and reached at the https address
/// `front` answers with (`front(consolePort, net, children)`): built, or
/// with `live`, by the dev server, redrawn as its source changes. `pdsEnv`
/// is the PDS's environment beyond this one's. Its parts, and `stop`.
export async function start({ accounts, front, pdsEnv = {}, live = false }) {
/// is the PDS's environment beyond this one's; `handleDomain`, the domain
/// its groups' handles and addresses are under. Its parts, and `stop`.
export async function start({
accounts,
front,
pdsEnv = {},
live = false,
handleDomain = '.groups.test'
}) {
const children = [];
const icons = await favicons();
const stop = () => {
@@ -136,7 +143,7 @@ export async function start({ accounts, front, pdsEnv = {}, live = false }) {
DATA_DIR: mkdtempSync(join(tmpdir(), 'group-host-world-')),
PLC_URL: net.plc,
DID_WEB_SCHEME: 'http',
HANDLE_DOMAIN: '.groups.test',
HANDLE_DOMAIN: handleDomain,
HANDLE_RESOLVERS: net.pds
}
});
@@ -176,7 +183,7 @@ export async function start({ accounts, front, pdsEnv = {}, live = false }) {
'content-type': 'application/json',
authorization: `Bearer ${await serviceAuth(net.pds, alice, did, lxm)}`
},
body: JSON.stringify({ handle: 'riders.groups.test', displayName: 'Riders' })
body: JSON.stringify({ handle: `riders${handleDomain}`, displayName: 'Riders' })
});
if (!made.ok) throw new Error(`createGroup: ${await made.text()}`);
const riders = await made.json();