i dont think this supports connecting to any service to cloudflare? such as d1, r2 object storage
i dont think this supports connecting to any service to cloudflare? such as d1, r2 object storage
if ( request.headers.get( 'cookie' ).includes( ... ) ) return fetch( request ). (aware we can check cookies in the rule, but that only 'fixes' things for a small percent of our traffic)if ( request.headers.get( 'cookie' ).includes(This is going to throw an exception for any request not containing the cookie header
( request.headers.get( 'cookie' ) || '' ).includes*:"Error: bleh\n at fetch (52624/snippet.js:6:13)\n
connect. When closing a browser obtained that way, it will still keep the session available for additional connect calls.npm i @ffmpeg/ffmpeg @ffmpeg/core)node_modules)run_worker_first = true to your configASSETS) and then call through to it: return env.ASSETS.fetch(request);if ( request.headers.get( 'cookie' ).includes( ... ) ) return fetch( request )( request.headers.get( 'cookie' ) || '' ).includesconnectconnectnpm i @ffmpeg/ffmpeg @ffmpeg/coreTotal Upload: 31672.57 KiB / gzip: 10087.55 KiB
Worker Startup Time: 45 ms
No bindings found.
Uploaded ffmpeg-example (10.47 sec)
Deployed ffmpeg-example triggers (2.74 sec)⛅️ wrangler 4.16.1
-------------------
Total Upload: 31652.23 KiB / gzip: 10083.07 KiB
No bindings found.
▲ [WARNING] Here are the 3 largest dependencies included in your script:
- node_modules/@ffmpeg/core/dist/esm/ffmpeg-core.wasm - 31476.97 KiB
- node_modules/@ffmpeg/core/dist/esm/ffmpeg-core.js - 173.98 KiB
- src/index.ts - 1.01 KiB
If these are unnecessary, consider removing them
✘ [ERROR] A request to the Cloudflare API (/accounts/.../workers/scripts/workers-test/versions) failed.
Your Worker exceeded the size limit of 3 MiB. Please upgrade to a paid plan to
deploy Workers up to 10 MiB.
https://dash.cloudflare.com/.../workers/plans
[code: 10027]
To learn more about this error, visit:
https://developers.cloudflare.com/workers/platform/limits/#worker-size
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/chooserun_worker_first = trueASSETSreturn env.ASSETS.fetch(request); try {
throw new Error("bleh")
return fetch(request);
}
catch (err) {
var response = await fetch(request);
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.set("error", JSON.stringify({ message: err.message, name: err.name, stack: err.stack, ...err }))
return modifiedResponse;
}import { acquire, connect } from '@cloudflare/playwright';
export default {
async fetch(request: Request, env: Env) {
// ensures session is acquired and kept alive for 20 seconds
const { sessionId } = await acquire(env.MYBROWSER, { keep_alive: 20_000 });
const browser = await connect(env.MYBROWSER, sessionId);
// use the browser normally
// it closes this browser instance but keeps the session alive
await browser.close();
// another browser instance can connect to the same session
const otherBrowser = await connect(env.MYBROWSER, sessionId);
// use the other browser instance with the same session
await otherBrowser.close();
// session is automatically closed after 20 seconds of inactivity
},
};// @ts-ignore
import createFFmpegCore from '@ffmpeg/core';
// @ts-ignore
import wasm from '../node_modules/@ffmpeg/core/dist/esm/ffmpeg-core.wasm';
import type { FFmpegCoreModule } from '@ffmpeg/types';
// for some reason, ffmpeg-core tries to access location.href...
(globalThis as any).location = { href: 'https://example.com' };
const mod = {
instantiateWasm: async (info: any, receiveInstance: any) => {
const instance = await WebAssembly.instantiate(wasm, info);
receiveInstance(instance);
}
};
const ffmpeg = await createFFmpegCore(mod) as FFmpegCoreModule;
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const videoFile = new URL(request.url).searchParams.get('video')
?? 'https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm';
const input = await fetch(videoFile);
ffmpeg.FS.writeFile('input.mp4', await input.bytes());
ffmpeg.exec('-i', 'input.mp4', '-vf', 'format=gray', 'output.mp4');
const output = ffmpeg.FS.readFile('output.mp4', { encoding: 'binary' });
ffmpeg.FS.unlink('input.mp4');
ffmpeg.FS.unlink('output.mp4');
return new Response(output, {
headers: {
'Content-Type': 'video/mp4',
},
});
},
};export default {
fetch: async (
request: Request,
env: { JWT_SECRET: string }
): Promise<Response> => {
const token = request.headers.get("authorization");
if (!token) {
return new Response("unauthorized", { status: 401 });
}
try {
await validateJWT(token, env.JWT_SECRET);
return new Response(null, {
status: 404 // meant as success for cloudflare to serve assets
});
} catch {
return new Response("forbidden", { status: 403 });
}
}
};