INTEGRATIONS / SERVER INTEGRATION

pageflock, meet Next.js.

Keep pageflock credentials on the server, fetch only when your application requests work, and return the fields your UI needs.

← All integrations

Your first connection.

  1. 01

    Add WAGGLE_API_KEY to .env.local or your hosting secret store. Do not prefix it with NEXT_PUBLIC_. Install the server-only package in your app.

  2. 02

    Save the helper below as lib/waggle.ts. Import it only from server code, such as an authenticated Route Handler or a background job.

  3. 03

    Call extractPage after your own session and quota checks. Do not expose an unauthenticated proxy or automatically spend credits during page rendering or prefetching.

Tool reference: Next.js documentation ↗

Build the request.

Set the environment variables in your terminal for these code examples. In automation tools, enter the URL and credentials in the tool’s own fields.

lib/waggle.tsTypeScript · server only
import "server-only";

// Call from an authenticated server workflow, after your own quota checks.
// This helper does not create a public route or an automatic page-render fetch.
export async function extractPage(url: string): Promise<unknown> {
  const apiKey = process.env.WAGGLE_API_KEY;
  if (!apiKey) throw new Error("Set WAGGLE_API_KEY on the server");
  const response = await fetch("https://pageflock.hyvelabs.tech/api/pageflock/v1/scrape", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ url }),
    cache: "no-store",
    signal: AbortSignal.timeout(45000),
  });
  const result: unknown = await response.json();
  if (!response.ok) {
    throw new Error(`pageflock HTTP ${response.status}: ${JSON.stringify(result)}`);
  }
  return result;
}

Reading or copying this example does not send a request or use credits.

YOUR PRIVACY

Choose what works for you. You can reopen these settings from the footer at any time.