Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mise exec -- pnpm db:migrate
mise exec -- just dev
```

Open **http://localhost:5173/console/**. Vite+ serves the console and forwards other paths to the local Worker on port 8787, including mapped repository URLs. Wrangler emulates D1, R2, and Durable Objects locally. The example secrets are for local development only.
Open **http://localhost:5173/#/**. Vite+ serves the console page at `/` and forwards other paths to the local Worker on port 8787, including mapped repository URLs. Wrangler emulates D1, R2, and Durable Objects locally. The example secrets are for local development only.

Initialize the local instance once:

Expand Down Expand Up @@ -221,7 +221,7 @@ Mappings work in both instance modes. Each URL selects exactly one repository. T

Relative URLs start with a single slash. Absolute URLs must use HTTPS, except HTTP on `localhost`, `127.0.0.1`, or `[::1]` for local development. Matching uses the exact origin and the longest matching path prefix at a slash boundary, so `/snapshots` takes precedence over a root mapping. A missing artifact in that repository returns 404 without falling back to another repository. Trailing slashes are optional; duplicate URLs are rejected. `/api`, `/maven`, `/console`, `/health`, `/invite`, `/favicon.ico`, `/robots.txt`, and `/.well-known` are reserved, including their descendants. Nested mappings also reserve their prefixes in the parent mapping; artifacts shadowed by these prefixes remain available at the canonical `/maven/...` URL.

The console lives at `/console` and `/` redirects there. `APP_URL` remains the console's origin, without `/console`; OAuth callback URLs stay under `/api/auth`. Existing invitation links under `/invite` redirect to `/console/invite`. Other old console bookmarks need the `/console` prefix. The console displays the first configured mapping for a repository in copyable URLs and dependency snippets, falling back to its canonical URL when no mapping exists. Browser download buttons use the console origin so session credentials work even when a mapping uses another hostname.
The console is served from `/` and routes with a URL hash, for example `/#/default/repositories`, so root mappings and console pages share the origin without ambiguity. Its assets stay under `/console/assets/`, and old `/console/...` bookmarks and `/invite` links redirect to the matching `/#/...` route. `APP_URL` is the console's origin; OAuth callback URLs stay under `/api/auth`. The console displays the first configured mapping for a repository in copyable URLs and dependency snippets, falling back to its canonical URL when no mapping exists. Browser download buttons use the console origin so session credentials work even when a mapping uses another hostname.

## Initial implementation boundaries

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export function App() {
small
onClick={async () => {
await authClient.signOut();
location.assign("/console");
history.replaceState(null, "", "/#/");
location.reload();
}}
>
Sign out
Expand Down
14 changes: 11 additions & 3 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router";
import { HashRouter } from "react-router";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { App } from "./app";
import "./global.css";

if (import.meta.env.DEV) void import("virtual:stylex:runtime");

// Canonicalize "/" and "/#" to "/#/", and old "/console/..." bookmarks to their hash routes.
if (location.pathname !== "/" || !location.hash.startsWith("#/")) {
const route = location.hash.startsWith("#/")
? location.hash.slice(1)
: (location.pathname.replace(/^\/console(?=\/|$)/, "") || "/") + location.search;
history.replaceState(null, "", "/#" + route);
}

const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 15_000, retry: 1 } },
});
createRoot(document.getElementById("root")!).render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<BrowserRouter basename="/console">
<HashRouter>
<App />
</BrowserRouter>
</HashRouter>
</QueryClientProvider>
</StrictMode>,
);
7 changes: 6 additions & 1 deletion apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export default defineConfig({
port: 5173,
strictPort: true,
proxy: {
"^/(?!console(?:/|$))": "http://127.0.0.1:8787",
// Serve the console page at / and forward every other non-console path to the Worker
// with the original host, so origin-relative repository mappings resolve locally.
"^/(?!console(?:/|$))": {
target: "http://127.0.0.1:8787",
bypass: (req) => (req.url === "/" ? "/console/" : undefined),
},
},
},
});
19 changes: 15 additions & 4 deletions apps/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,25 @@ app.doc("/api/openapi.json", {
});
app.all("/api/*", (c) => c.json({ error: "Not found" }, 404));
app.all("/maven/*", (c) => c.json({ error: "Publish through the local maven-r2 proxy" }, 405));
app.get("/", (c) => c.redirect(new URL("/console", c.env.APP_URL).href));
app.get("/invite/:secret", (c) => c.redirect(new URL("/console" + c.req.path, c.env.APP_URL).href));
app.on(["GET", "HEAD"], ["/console", "/console/*"], async (c) => {
// The console is a hash-routed single page at /#/...; its hashed assets live under /console/assets/.
const consoleUrl = (env: Env, route: string) => new URL("/#" + route, env.APP_URL).href;
app.on(["GET", "HEAD"], "/", async (c) => {
const url = new URL(c.req.url);
if (!url.pathname.startsWith("/console/assets/")) url.pathname = "/console/index.html";
if (url.origin !== new URL(c.env.APP_URL).origin) return c.redirect(consoleUrl(c.env, "/"));
url.pathname = "/console/index.html";
const response = await c.env.ASSETS.fetch(new Request(url, c.req.raw));
return new Response(response.body, response);
});
app.get("/invite/:secret", (c) => c.redirect(consoleUrl(c.env, c.req.path)));
app.on(["GET", "HEAD"], ["/console", "/console/*"], async (c) => {
const url = new URL(c.req.url);
if (!url.pathname.startsWith("/console/assets/"))
return c.redirect(
consoleUrl(c.env, (url.pathname.slice("/console".length) || "/") + url.search),
);
const response = await c.env.ASSETS.fetch(c.req.raw);
return new Response(response.body, response);
});
for (const probe of ["/favicon.ico", "/robots.txt", "/.well-known/*"])
app.all(probe, (c) => c.json({ error: "Not found" }, 404));
app.all("*", serveMappedRepository);
Expand Down
2 changes: 1 addition & 1 deletion apps/worker/src/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export function registerManagement(app: OpenAPIHono<AppEnv>) {
return c.json(
{
id,
url: new URL("/console/invite/" + secret, c.env.APP_URL).href,
url: new URL("/#/invite/" + secret, c.env.APP_URL).href,
expiresAt: expires,
},
201,
Expand Down
32 changes: 17 additions & 15 deletions apps/worker/test/publication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe("repository URL mappings", () => {
"artifact",
);
expect((await app.request("https://other.test" + path, {}, mapped)).status).toBe(404);
expect((await app.request("https://repo.test/", {}, mapped)).status).toBe(302);
expect((await app.request("https://other.test/", {}, mapped)).status).toBe(302);
expect((await app.request("https://repo.test/snapshots", {}, mapped)).status).toBe(404);
expect(
await json(
Expand Down Expand Up @@ -438,25 +438,26 @@ describe("repository URL mappings", () => {
} as Fetcher,
};
expect((await app.request("https://other.test/", {}, mapped)).headers.get("location")).toBe(
"https://repo.test/console",
"https://repo.test/#/",
);
expect(await (await app.request("https://repo.test/", {}, mapped)).text()).toBe(
"/console/index.html",
);
expect(
await (
await app.request(
"https://repo.test/console/test/repositories/releases",
{},
mapped,
)
).text(),
).toBe("/console/index.html");
expect(
await (await app.request("https://repo.test/console/assets/app.js", {}, mapped)).text(),
).toBe("/console/assets/app.js");
const location = async (url: string) =>
(await app.request(url, {}, mapped)).headers.get("location");
expect(await location("https://repo.test/console")).toBe("https://repo.test/#/");
expect(
(await app.request("https://other.test/invite/example", {}, mapped)).headers.get(
"location",
),
).toBe("https://repo.test/console/invite/example");
await location("https://repo.test/console/test/repositories/releases?prefix=com/acme"),
).toBe("https://repo.test/#/test/repositories/releases?prefix=com/acme");
expect(await location("https://repo.test/console/invite/example")).toBe(
"https://repo.test/#/invite/example",
);
expect(await location("https://other.test/invite/example")).toBe(
"https://repo.test/#/invite/example",
);
const favicon = await app.request("https://repo.test/favicon.ico", {}, mapped);
expect(favicon.status).toBe(404);
expect(favicon.headers.has("www-authenticate")).toBe(false);
Expand Down Expand Up @@ -652,6 +653,7 @@ describe("account management and lifecycle", () => {
}),
201,
);
expect(invitation.url).toMatch(/^https:\/\/repo\.test\/#\/invite\/[^/]+$/);
const secret = invitation.url.split("/").at(-1);
expect((await owner("/api/invitations/accept", "POST", { secret })).status).toBe(404);
await json(await guest("/api/invitations/accept", "POST", { secret }));
Expand Down
13 changes: 6 additions & 7 deletions scripts/interop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,13 @@ try {
const page = await context.newPage(),
errors = [];
page.on("pageerror", (error) => errors.push(error.message));
await page.goto(origin + "/console/test");
await page.goto(origin + "/#/test");
await expect(page.getByRole("heading", { name: "Repositories", exact: true })).toBeVisible();
await expect(page.getByRole("link", { name: "Releases", exact: true })).toBeVisible();
const screenshots = join(root, ".artifacts");
await mkdir(screenshots, { recursive: true });
await page.screenshot({ path: join(screenshots, "repositories.png"), fullPage: true });
await page.goto(
origin + "/console/test/repositories/releases?prefix=com/example/mavenr2/core/1.0.0",
);
await page.goto(origin + "/#/test/repositories/releases?prefix=com/example/mavenr2/core/1.0.0");
await expect(page.getByRole("button", { name: "core-1.0.0.pom", exact: true })).toBeVisible();
await expect(page.locator("pre").filter({ hasText: "repositories {" })).toContainText(
'password = providers.environmentVariable("MAVEN_R2_READ_TOKEN").get()',
Expand All @@ -269,7 +267,7 @@ try {
SELECT repository_id,'zz/qa/1.0/qa-1.0-' || n || '.pom',object_key,size,sha256,checksums,publication_id,updated_at
FROM files CROSS JOIN fixture WHERE path='com/example/mavenr2/core/1.0.0/core-1.0.0.pom';
`);
await page.goto(origin + "/console/test/repositories/releases");
await page.goto(origin + "/#/test/repositories/releases");
await page.getByRole("button", { name: "Next page", exact: true }).click();
await expect(page).toHaveURL(/after=/);
await page.getByRole("searchbox", { name: "Search artifact paths" }).fill("core-1.0.0.pom");
Expand All @@ -279,8 +277,8 @@ try {
exact: true,
}),
).toBeVisible();
assert.equal(new URL(page.url()).searchParams.has("after"), false);
await page.goto(origin + "/console/test/tokens");
assert.ok(!page.url().includes("after="));
await page.goto(origin + "/#/test/tokens");
await page.getByRole("button", { name: "Create token", exact: true }).click();
const dialog = page.getByRole("dialog");
await dialog.getByLabel("Token name").fill("Browser verification");
Expand All @@ -293,6 +291,7 @@ try {
await expect(page.getByText("Revoked", { exact: true })).toBeVisible();
await page.setViewportSize({ width: 390, height: 844 });
await page.goto(origin + "/console/test");
await expect(page).toHaveURL(origin + "/#/test");
await expect(page.getByRole("heading", { name: "Repositories", exact: true })).toBeVisible();
await page.screenshot({ path: join(screenshots, "mobile.png"), fullPage: true });
assert.ok(
Expand Down
Loading