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
22 changes: 8 additions & 14 deletions landing-page/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions landing-page/tests/sites-worker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,50 @@ import { access } from "node:fs/promises";
import test from "node:test";
import worker from "../worker/index.js";

test("permanently redirects product connector paths to canonical domains", async () => {
const cases = [
["/skills", "https://skillscanvas.co/"],
["/skills/passport?source=hub", "https://skillscanvas.co/passport?source=hub"],
["/concepts/ideas/42", "https://conceptsnexus.co/ideas/42"],
["/collab/capsules/demo", "https://collaboard.co/capsules/demo"],
["/vest/projects/demo", "https://vestden.co/projects/demo"],
];

for (const [pathname, expectedLocation] of cases) {
let assetCalls = 0;
const response = await worker.fetch(new Request(`https://fixars.ai${pathname}`), {
ASSETS: {
fetch: async () => {
assetCalls += 1;
return new Response("unexpected", { status: 500 });
},
},
});

assert.equal(response.status, 308);
assert.equal(response.headers.get("location"), expectedLocation);
assert.equal(assetCalls, 0);
}
});

test("does not redirect write requests through connector aliases", async () => {
let assetCalls = 0;
const response = await worker.fetch(
new Request("https://fixars.ai/skills/passport", { method: "POST" }),
{
ASSETS: {
fetch: async () => {
assetCalls += 1;
return new Response("missing", { status: 404 });
},
},
},
);

assert.equal(response.status, 404);
assert.equal(assetCalls, 1);
});

test("serves existing static assets without a fallback", async () => {
const calls = [];
const response = await worker.fetch(new Request("https://example.test/assets/app.js"), {
Expand Down
33 changes: 33 additions & 0 deletions landing-page/worker/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
const PRODUCT_CONNECTORS = new Map([
["skills", "https://skillscanvas.co"],
["concepts", "https://conceptsnexus.co"],
["collab", "https://collaboard.co"],
["vest", "https://vestden.co"],
]);

function productConnectorRedirect(request) {
if (!["GET", "HEAD"].includes(request.method)) {
return null;
}

const incomingUrl = new URL(request.url);
const [, connector, ...remainder] = incomingUrl.pathname.split("/");
const canonicalOrigin = PRODUCT_CONNECTORS.get(connector);

if (!canonicalOrigin) {
return null;
}

// These server-side connector paths are aliases only. Product domains remain
// canonical deployment origins; the suffix and query string cross intact.
const destination = new URL(canonicalOrigin);
destination.pathname = remainder.length ? `/${remainder.join("/")}` : "/";
destination.search = incomingUrl.search;
return Response.redirect(destination, 308);
}

export default {
async fetch(request, env) {
const connectorRedirect = productConnectorRedirect(request);
if (connectorRedirect) {
return connectorRedirect;
}

const response = await env.ASSETS.fetch(request);
const acceptsHtml = request.headers.get("accept")?.includes("text/html");

Expand Down
Loading