Hey. Pages is still supported but longer term we want to get to a point where every new application
Hey. Pages is still supported but longer term we want to get to a point where every new application can be built on Workers
@vercel/og inside a worker. But @cloudflare/pages-plugin-vercel-og uses an older version. npx wrangler dev --remoteblock POST requests, await fetch("https://tunnel.xxx.com/authentication", works on cloudflarenpx wrangler dev --remote on this same request i get (403) Forbidden as responsetest.com, worker worker.test.com fetching origin.test.com is a "same zone subrequest"Simultaneous open connections
You can open up to six connections simultaneously, for each invocation of your Worker. The connections opened by the following API calls all count toward this limit:
- the fetch() method of the Fetch API.const results = await Promise.all([
fetch(url1),
fetch(url2),
fetch(url3),
fetch(url4),
fetch(url5),
fetch(url6),
fetch(url7), // Exceeds the limit of 6
]);export default {
async fetch(req, env): Promise<Response>
{
// https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/
const ipAddress = req.headers.get("cf-connecting-ip") || "";
const { success } = await env.MY_RATE_LIMITER.limit({ key: ipAddress })
if (!success)
return new Response(`429 Failure – rate limit exceeded for ${ipAddress}`, { status: 429 });interface Env
{
MY_RATE_LIMITER: any;
}
export default {
async fetch(req, env): Promise<Response>
{
// https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/
const ipAddress = req.headers.get("cf-connecting-ip") || "";
const { success } = await env.MY_RATE_LIMITER.limit({ key: ipAddress })
if (!success)
return new Response(`429 Failure – rate limit exceeded for ${ipAddress}`, { status: 429 });
const login = req.headers.get("x-login");
const password = req.headers.get("x-password");
if (!login || !password)
return new Response("", { status: 403 });
const isValidUser = await validateUser(login, password);
if (!isValidUser)
return new Response("", { status: 403 });
//const origin = new Request(req.url, req);
//origin.headers.delete("x-login");
//origin.headers.delete('cf-workers-preview-token');
//return fetch(origin);
return fetch(req)
},
} satisfies ExportedHandler;
async function validateUser(login: string, password: string): Promise<boolean>
{
const response = await fetch("https://tunnel.xxx.com/authentication",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ login, password })
});
// The server returns 200 for valid authentication, 403 for invalid
return response.status === 200;
}