fix: nextjs sdk to allow pass query string
This commit is contained in:
@@ -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',
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user