fix: nextjs sdk to allow pass query string

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-25 10:36:57 +01:00
parent 4f9d66693e
commit 86903b1937
2 changed files with 9 additions and 4 deletions

View File

@@ -44,18 +44,23 @@ export function createNextRouteHandler(
export function createScriptHandler() { export function createScriptHandler() {
return async function GET(req: Request) { return async function GET(req: Request) {
if (!req.url.endsWith('op1.js')) { const url = new URL(req.url);
const query = url.searchParams.toString();
if (!url.pathname.endsWith('op1.js')) {
return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ error: 'Not found' }, { status: 404 });
} }
const scriptUrl = 'https://openpanel.dev/op1.js'; const scriptUrl = 'https://openpanel.dev/op1.js';
try { try {
const res = await fetch(scriptUrl, { const res = await fetch(scriptUrl, {
// @ts-expect-error // @ts-ignore
next: { revalidate: 86400 }, next: { revalidate: 86400 },
}); });
const text = await res.text(); const text = await res.text();
const etag = `"${createHash('md5').update(text).digest('hex')}"`; const etag = `"${createHash('md5')
.update(text + query)
.digest('hex')}"`;
return new NextResponse(text, { return new NextResponse(text, {
headers: { headers: {
'Content-Type': 'text/javascript', 'Content-Type': 'text/javascript',

View File

@@ -1,6 +1,6 @@
{ {
"name": "@openpanel/nextjs", "name": "@openpanel/nextjs",
"version": "1.0.19-local", "version": "1.0.20-local",
"module": "index.ts", "module": "index.ts",
"scripts": { "scripts": {
"build": "rm -rf dist && tsup", "build": "rm -rf dist && tsup",