Fetch recorder settings from website config endpoint
This commit is contained in:
1 parent
c724f42daf
commit
c6733897b4
4 files changed
+88
-18
No files matched your search
@@ -42,9 +42,7 @@ export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) {
|
||||
? `${process.env.cloudUrl}/${RECORDER_NAME}`
|
||||
: `${window?.location?.origin || ''}${process.env.basePath || ''}/${RECORDER_NAME}`;
|
||||
|
||||
let recorderAttrs = `data-website-id="${websiteId}" data-sample-rate="${sampleRate}" data-mask-level="${maskLevel}" data-max-duration="${parseInt(maxDuration, 10) || 300000}"`;
|
||||
if (blockSelector) recorderAttrs += ` data-block-selector="${blockSelector}"`;
|
||||
const recorderCode = `<script defer src="${recorderUrl}" ${recorderAttrs}></script>`;
|
||||
const recorderCode = `<script defer src="${recorderUrl}" data-website-id="${websiteId}"></script>`;
|
||||
|
||||
const handleToggle = async (value: boolean) => {
|
||||
const previous = enabled;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json } from '@/lib/response';
|
||||
import { getWebsite } from '@/queries/prisma';
|
||||
|
||||
interface ReplayConfig {
|
||||
sampleRate?: number;
|
||||
maskLevel?: string;
|
||||
maxDuration?: number;
|
||||
blockSelector?: string;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const { error } = await parseRequest(request, null, { skipAuth: true });
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const website = await getWebsite(websiteId);
|
||||
|
||||
const headers = {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=300',
|
||||
};
|
||||
|
||||
if (!website || !website.replayEnabled) {
|
||||
return Response.json({ enabled: false }, { headers });
|
||||
}
|
||||
|
||||
const config = (website.replayConfig as ReplayConfig) || {};
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
enabled: true,
|
||||
sampleRate: config.sampleRate ?? 0.15,
|
||||
maskLevel: config.maskLevel ?? 'moderate',
|
||||
maxDuration: config.maxDuration ?? 300000,
|
||||
blockSelector: config.blockSelector ?? '',
|
||||
},
|
||||
{ headers },
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user