UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

46 lines (45 loc) 1.43 kB
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { generateNonce } from "../lib/utils"; export const DefaultRequestInfoDocument = ({ children }) => (_jsx(_Fragment, { children: children })); /** * Constructs a generic requestInfo that can be used as defaults. * Allows for passing in overrides to initialize with defaults. */ export const constructWithDefaultRequestInfo = (overrides = {}) => { const { rw: rwOverrides, ...otherRequestInfoOverrides } = overrides; const defaultRequestInfo = { request: new Request("http://localhost/"), path: "/", params: {}, ctx: {}, cf: { waitUntil: () => { }, passThroughOnException: () => { }, props: {}, }, response: { status: 200, headers: new Headers(), }, isAction: false, rw: { Document: DefaultRequestInfoDocument, nonce: generateNonce(), rscPayload: true, ssr: true, databases: new Map(), scriptsToBeLoaded: new Set(), entryScripts: new Set(), inlineScripts: new Set(), pageRouteResolved: undefined, }, }; return { ...defaultRequestInfo, ...otherRequestInfoOverrides, rw: { ...defaultRequestInfo.rw, ...rwOverrides, }, }; };