Skip to content

fix(repoData): correctly extract server names #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion app/routes/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ export const loader = async ({ request }: { request: Request }) => {
const url = new URL(request.url);
const host = url.host;
const pathname = url.pathname;
const protocol = url.protocol;

const { urlType, owner, repo } = getRepoData({
requestHost: host,
requestUrl: pathname,
});

return { urlType, owner, repo, url: url.toString() };
let urlString = url.toString();

if (urlType == "github") {
urlString = `${protocol}//${host}/${owner}/${repo}`;
} else if (urlType == "subdomain") {
urlString = `${protocol}//${host}/${repo}`;
}

return { urlType, owner, repo, url: urlString };
};

export function HydrateFallback() {
Expand Down
32 changes: 32 additions & 0 deletions src/shared/repoData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ const testCases: {
host: "gitmcp.io",
},
},
{
title: "long gitmcp.io",
input: {
requestHost: "gitmcp.io",
requestUrls: [
"https://gitmcp.io/mrdoob/three.js/test",
"/mrdoob/three.js/test",
],
},
expected: {
owner: "mrdoob",
repo: "three.js",
urlType: "github",
host: "gitmcp.io",
},
},
{
title: "myOwner.gitmcp.io",
input: {
Expand All @@ -49,6 +65,22 @@ const testCases: {
host: "ownerName.gitmcp.io",
},
},
{
title: "long myOwner.gitmcp.io",
input: {
requestHost: "keyboardkit.gitmcp.io",
requestUrls: [
"https://keyboardkit.gitmcp.io/KeyboardKit/documentation/keyboardkit",
"/KeyboardKit/documentation/keyboardkit",
],
},
expected: {
owner: "keyboardkit",
repo: "KeyboardKit",
urlType: "subdomain",
host: "keyboardkit.gitmcp.io",
},
},
{
title: "generic (docs)",
input: {
Expand Down
5 changes: 3 additions & 2 deletions src/shared/repoData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export function getRepoData(requestData: RequestData): RepoData {
// Check for subdomain pattern: {subdomain}.gitmcp.io/{path}
if (requestHost.includes(".gitmcp.io")) {
const subdomain = requestHost.split(".")[0];
const repo = path.split("/")?.at(0) ?? null;
logData.owner = subdomain;
logData.repo = path;
logData.repo = repo;
logData.urlType = "subdomain";
log("getRepoDataLog", JSON.stringify(logData, null, 2));

Expand All @@ -56,7 +57,7 @@ export function getRepoData(requestData: RequestData): RepoData {

return {
owner: subdomain,
repo: path || null,
repo: repo || null,
host: requestHost,
urlType: "subdomain",
};
Expand Down