Cоlе
12/09/2021, 9:44 PM--bindings
rightCоlе
12/09/2021, 9:44 PMCоlе
12/09/2021, 9:44 PMGreg Brimble | Cloudflare Pages
12/09/2021, 9:46 PMPagesFunction<{ KV: KVNamespace }, ‘param’, { mydata: number }>
Greg Brimble | Cloudflare Pages
12/09/2021, 9:46 PMCоlе
12/09/2021, 9:46 PMlucasnad27
12/09/2021, 9:54 PMFOO
with a value of BAR
could I access this env val with something as simple as const foo = FOO;
?lucasnad27
12/09/2021, 9:56 PMlucasnad27
12/09/2021, 10:05 PMexport const onRequestPost: PagesFunction<{ KV: KVNamespace }, 'param', { FOO : string }> = async ({
request,
env,
}) => {
return env.FOO
};
wrangler pages dev -b FOO=bar -- yarn dev
geelen
12/09/2021, 10:14 PMgeelen
12/09/2021, 10:15 PMgeelen
12/09/2021, 10:15 PMAdam Reed
12/09/2021, 10:20 PMAdam Reed
12/09/2021, 10:20 PMAdam Reed
12/09/2021, 10:20 PMAdam Reed
12/09/2021, 10:20 PMJustinNoel
12/09/2021, 10:32 PMimport { AwsClient } from "aws4fetch";
// These are the only environment variables I expect to be available.
type Env = {
B2_ACCESS_KEY_ID: string;
B2_SECRET_ACCESS_KEY: string;
};
// My "route" should have an id
// Since this is a GET, there is no data.
export const onRequestGet: PagesFunction<Env, "id", Record<string, unknown>> = async ({
env,
params,
}) => {
const { B2_ACCESS_KEY_ID, B2_SECRET_ACCESS_KEY } = env;
const aws = new AwsClient({
accessKeyId: B2_ACCESS_KEY_ID,
secretAccessKey: B2_SECRET_ACCESS_KEY,
region: "my-bucket-name.s3.us-west-001.backblazeb2.com",
});
try {
const id = params?.id;
if (!id) {
return new Response("Bad Request", { status: 400 });
}
const documentUrl = `https://${aws.region}/${id}`;
const signedRequest = await aws.sign(documentUrl);
return await fetch(signedRequest);
} catch (e) {
console.log(e);
return new Response("Server Error", { status: 503 });
}
};
saibotsivad
12/10/2021, 3:42 AMErwin
12/10/2021, 3:52 AMstripe-workers
package with the custom Webpack config and then import that in Pages.saibotsivad
12/10/2021, 3:54 AMsaibotsivad
12/10/2021, 3:59 AMErwin
12/10/2021, 4:01 AMErwin
12/10/2021, 4:01 AMnpx wrangler@beta pages dev
to run everything either on the edge or locally in miniflareErwin
12/10/2021, 4:01 AMsaibotsivad
12/10/2021, 4:03 AMsaibotsivad
12/10/2021, 4:03 AMsaibotsivad
12/10/2021, 4:04 AMErwin
12/10/2021, 4:04 AMsaibotsivad
12/10/2021, 4:04 AMalbert
12/10/2021, 8:43 AMTypeError: Cannot reconstruct a Request with a used body.
when the POST body is not empty.
mjs
export const onRequestPost = async ({request, env}) => {
await request.text()
return new Response('OK :)')
}
I do not use the body in middleware.
mjs
export const onRequest = async ({next}) => {
try {
return await next()
} catch (error) {
return new Response(error, {status: 500, statusText: 'Albert Wrote Bad Code'})
}
}
This seems like a bug :/