Skip to content
32 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

The phone app's scaffolding, in apps/mobile: Expo SDK 57 with Expo Router, Android first, with Chat, Code and Customize. It signs in with g1t's own OAuth 2.1 (PKCE, a client id that encodes "g1t for Android" and g1t://oauth/callback, so nothing is registered), keeps the server and credentials in the phone's keystore, refreshes the 30-day token a minute early and shares the single-use refresh between requests. A personal access token is the other way in, and a self-hosted g1t the other server.1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { HOSTED, apiFor, parseOrigin, parseServer, socketUrl } from "./server.ts";
5
6test("an origin is all that is kept", () => {
7 assert.equal(parseOrigin("https://g1t.sh/acme/-/chat?x#y"), "https://g1t.sh");
8 assert.equal(parseOrigin(" g1t.example.com "), "https://g1t.example.com");
9 assert.equal(parseOrigin("http://192.168.1.20:5173/login"), "http://192.168.1.20:5173");
10 assert.equal(parseOrigin("ftp://g1t.sh"), null);
11 assert.equal(parseOrigin("not a url at all"), null);
12 assert.equal(parseOrigin(""), null);
13});
14
15test("hosted g1t's API is api.g1t.sh, and a self-hosted one's is api. on its host", () => {
16 assert.equal(apiFor("https://g1t.sh"), "https://api.g1t.sh");
17 assert.equal(apiFor("https://g1t.example.com"), "https://api.g1t.example.com");
18 assert.deepEqual(parseServer("g1t.sh"), HOSTED);
19});
20
21test("an API given by hand wins", () => {
22 assert.deepEqual(parseServer("http://localhost:5173", "http://localhost:8789/"), {
23 site: "http://localhost:5173",
24 api: "http://localhost:8789",
25 });
26 assert.equal(parseServer("g1t.sh", "javascript:alert(1)"), null);
27});
28
29test("sockets follow the site's scheme", () => {
30 assert.equal(socketUrl(HOSTED, "/acme/-/chat/live?channel=chn_1"), "wss://g1t.sh/acme/-/chat/live?channel=chn_1");
31 assert.equal(socketUrl({ site: "http://localhost:5173", api: "" }, "/-/live"), "ws://localhost:5173/-/live");
32});