Skip to content

Commit 5620134

Browse files
committed
fix: stop building urls server side
1 parent d953c3c commit 5620134

2 files changed

Lines changed: 21 additions & 35 deletions

File tree

packages/app/app/components/Commits.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ async function goPrevPage() {
187187
}
188188
await fetchPage(currentPage.value - 1);
189189
}
190+
191+
// Build install snippet on the client so the URL always uses the real public
192+
// origin (window.location.origin) instead of a host resolved during SSR, which
193+
// can be `localhost` for internal Nitro dispatches on Cloudflare.
194+
function buildInstallMarkdown(
195+
commit: (typeof commitsWithRelease.value)[number] | null,
196+
) {
197+
if (!commit) return "";
198+
const origin =
199+
typeof window !== "undefined" ? window.location.origin : "";
200+
const packages: string[] = commit.release.packages ?? [];
201+
return packages
202+
.map((pkg) => {
203+
const shorter = props.repo === pkg;
204+
const repoSegment = shorter ? "" : `/${props.repo}`;
205+
return `\`\`\`\nnpm i ${origin}/${props.owner}${repoSegment}/${pkg}@${commit.abbreviatedOid}\n\`\`\``;
206+
})
207+
.join("\n\n");
208+
}
190209
</script>
191210

192211
<template>
@@ -358,7 +377,7 @@ async function goPrevPage() {
358377

359378
<div
360379
class="max-w-full p-4 overflow-x-auto border border-gray-100 dark:border-gray-800 rounded-lg prose dark:prose-invert flex flex-col gap-2"
361-
v-html="marked(selectedCommit.release.text)"
380+
v-html="marked(buildInstallMarkdown(selectedCommit))"
362381
/>
363382
</div>
364383
</template>

packages/app/server/api/repo/commits.get.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { H3Event } from "h3";
22
import { z } from "zod";
3-
import type { PackageManager } from "@pkg-pr-new/utils";
4-
import { generateCommitPublishMessage } from "../../utils/markdown";
53
import {
64
useBinding,
75
useCursorsBucket,
@@ -128,30 +126,6 @@ async function getDefaultBranchInfo(
128126
};
129127
}
130128

131-
function makeReleaseText(
132-
origin: string,
133-
owner: string,
134-
repo: string,
135-
sha: string,
136-
packages: string[],
137-
) {
138-
return generateCommitPublishMessage(
139-
origin,
140-
{},
141-
packages,
142-
{
143-
owner,
144-
repo,
145-
sha,
146-
ref: sha,
147-
},
148-
false,
149-
"npm" satisfies PackageManager,
150-
false,
151-
false,
152-
).trim();
153-
}
154-
155129
export default defineEventHandler(async (event) => {
156130
try {
157131
const query = await getValidatedQuery(event, (data) =>
@@ -237,7 +211,6 @@ export default defineEventHandler(async (event) => {
237211
const nextCursor = hasNextPage ? String(page + 1) : null;
238212
const totalCount = releases.length;
239213
const totalPages = Math.max(1, Math.ceil(totalCount / perPage));
240-
const origin = getRequestURL(event).origin;
241214
const commitMetadata = await getCommitMetadata(
242215
installation,
243216
query.owner,
@@ -284,13 +257,7 @@ export default defineEventHandler(async (event) => {
284257
name: "Continuous Releases",
285258
title: "Continuous Releases",
286259
summary: `Published ${sortedPackages.length} package(s)`,
287-
text: makeReleaseText(
288-
origin,
289-
query.owner,
290-
query.repo,
291-
row.sha,
292-
sortedPackages,
293-
),
260+
packages: sortedPackages,
294261
detailsUrl: `https://github.com/${query.owner}/${query.repo}/commit/${row.sha}`,
295262
url: `https://github.com/${query.owner}/${query.repo}/commit/${row.sha}`,
296263
},

0 commit comments

Comments
 (0)