Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/builders/src/base-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,20 +671,26 @@ export const POST = workflowEntrypoint(workflowCode);`;
* Creates a webhook handler bundle for resuming workflows via HTTP callbacks.
*
* @param bundle - If true, bundles dependencies (needed for Build Output API)
* @param suppressUndefinedRejections - If true, suppresses undefined rejections.
* This is a workaround to avoid crashing in local
* dev when context isn't set for waitUntil()
*/
protected async createWebhookBundle({
outfile,
bundle = false,
suppressUndefinedRejections = false,
}: {
outfile: string;
bundle?: boolean;
suppressUndefinedRejections?: boolean;
}): Promise<void> {
console.log('Creating webhook route');
await mkdir(dirname(outfile), { recursive: true });

// Create a static route that calls resumeWebhook
// This route works for both Next.js and Vercel Build Output API
const routeContent = `import { resumeWebhook } from 'workflow/api';
const routeContent = `${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });\n' : ''}
import { resumeWebhook } from 'workflow/api';

async function handler(request) {
const url = new URL(request.url);
Expand Down Expand Up @@ -725,7 +731,7 @@ export const OPTIONS = handler;`;
const webhookBundleStart = Date.now();
const result = await esbuild.build({
banner: {
js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n',
js: `// biome-ignore-all lint: generated file\n/* eslint-disable */`,
},
stdin: {
contents: routeContent,
Expand Down
5 changes: 1 addition & 4 deletions packages/sveltekit/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,12 @@ export const POST = async ({request}) => {
await this.createWebhookBundle({
outfile: webhookRouteFile,
bundle: false, // SvelteKit will handle bundling
suppressUndefinedRejections: true,
});

// Post-process the generated file to wrap with SvelteKit request converter
let webhookRouteContent = await readFile(webhookRouteFile, 'utf-8');

// NOTE: This is a workaround to avoid crashing in local dev when context isn't set for waitUntil()
webhookRouteContent = `process.on('unhandledRejection', (reason) => { if (reason !== undefined) console.error('Unhandled rejection detected', reason); });
${webhookRouteContent}`;

// Update handler signature to accept token as parameter
webhookRouteContent = webhookRouteContent.replace(
/async function handler\(request\) \{[\s\S]*?const token = decodeURIComponent\(pathParts\[pathParts\.length - 1\]\);/,
Expand Down
Loading