Walshy | Pages
04/28/2023, 5:56 PMJavaDad
04/28/2023, 9:24 PMtypescript
import { checkStoreSupportCode } from '../helpers/pocketbaseApi';
export function onRequestOptions() {
return new Response(null, {
status: 204,
headers: {
'content-type': 'application/json;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, HEAD, POST, OPTIONS',
'Access-Control-Allow-Headers': '*',
},
});
}
export async function onRequest({ request, env }) {
if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 });
}
const { supportCode } = await request.json();
if (!supportCode) {
return new Response('Missing support code', { status: 400 });
}
try {
const { status, error, storeHash } = await checkStoreSupportCode(supportCode, env);
if (error) {
return new Response(JSON.stringify({ status, error }));
}
return new Response(JSON.stringify({ status, storeHash }));
} catch (err) {
console.log(err);
return new Response(JSON.stringify({ status: 'error', error: 'An unknown error occured' }));
}
}
Dio
04/29/2023, 2:47 PMMiikaU
04/29/2023, 5:00 PMHubchicken
04/30/2023, 12:17 AMIEatBeans
04/30/2023, 7:11 AMnarumi
04/30/2023, 9:56 AM_headers
. Some browsers such as Firefox will positively send OPTIONS preflight for CORS.
However, pages will response with 405 Method Not Allowed error. The only solution I found is to add a middleware function to handle OPTIONS, but it will handle EVERY request, which is not desired.
So I wonder whether there is a way to handle OPTIONS requests only in functions, don't handle GET. Or settings somewhere I can turn on allowing CORS preflight. Thanks.
_headers
/*
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Headers: *
/*.json
Content-Type: application/json; charset=utf-8
functions/_middleware.js
All OPTIONS/GET requests will be handled by workers, and daily usage limit is easily reached.
https://developers.cloudflare.com/pages/platform/functions/examples/cors-headers/
export const onRequestOptions: PagesFunction = async () => {
return new Response(null, {
status: 204,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Max-Age': '86400',
},
});
};
Hubchicken
05/01/2023, 2:05 AMavalizadeh
05/01/2023, 12:10 PMsnaked
05/01/2023, 12:11 PMbret_pat
05/01/2023, 8:51 PMcedrick1227
05/02/2023, 1:42 AMDurian Gray
05/02/2023, 4:32 AM21:24:05.515 ⚡️ Completed `pnpx vercel build`.
21:24:08.831 ⚡️ Generated '.vercel/output/static/_worker.js'.
21:24:12.438 Finished
21:24:12.439 Found _worker.js in output directory. Uploading.
21:24:13.460 ✘ [ERROR] 1 error(s) and 0 warning(s) when compiling Worker.
21:24:13.461
21:24:13.462
21:24:13.465
21:24:13.467 ✘ [ERROR] Could not resolve "node:buffer"
21:24:13.468
21:24:13.468 _worker.js:2:4194:
21:24:13.468 2 │ ...ar ed={};import*as A_ from"node:buffer";var G5=Pt(()=>{Ce();$e()...
21:24:13.468 ╵ ~~~~~~~~~~~~~
21:24:13.468
21:24:13.468 The package "node:buffer" wasn't found on the file system but is built into node.
21:24:13.468 Add "node_compat = true" to your wrangler.toml file to enable Node compatibility.
21:24:13.468
21:24:13.469
21:24:13.470 ✘ [ERROR] Build failed with 1 error:
21:24:13.470
21:24:13.471 _worker.js:2:4194: ERROR: Could not resolve "node:buffer"
21:24:13.471
21:24:13.471
21:24:13.485 Failed building Pages Functions.
21:24:14.392 Failed: an internal error occurred
amit13
05/02/2023, 3:34 PMCLOUDFLARE_ACCOUNT_ID=<ACCOUNT_ID> npx wrangler pages publish <DIRECTORY> --project-name=<PROJECT_NAME>
How can i set the production environment variables at the time of deployment ?agarwalviraj
05/02/2023, 7:00 PMUncaught ReferenceError: navigator is not defined
each and every time, how should I fix this?
Thanks in advance.kulotskinakalbo
05/03/2023, 1:38 PMF0rce
05/03/2023, 5:00 PMdev
so I called the custom domain dev.<mydomain>
- as soon as I visit dev.<mydomain>
I have to enter my email and I receive a one-time-pin to access to preview deployment.
As soon as I enter the pin I am redirected to a site with an error. Better said I am redirected to an 404 because the wierd url is not found (see attached screenshot). Accessing the deployment via its hash or the "normal" pages.dev
url seems to work completely fine.
Am I doing something wrong ?
Thanks,
Davidiamawacko
05/04/2023, 4:51 AMthe script will never generate a response
in the logs. translated-website.pages.dev is the site, 01d53951-87de-4bc3-b18a-dd41e4799e6c is the deployment ID of the first failure, and my account ID is 3f360bad2082c7f61e0746eed6acfe55.rlnd
05/04/2023, 12:59 PMSimon Thorpe (securitypedant)
05/04/2023, 4:37 PMshapeshifter
05/04/2023, 5:30 PMshapeshifter
05/04/2023, 5:56 PMpeter-lustig
05/04/2023, 7:59 PMshapeshifter
05/04/2023, 9:09 PMDaveJ
05/04/2023, 9:47 PMhttps://next.todesktop.com/cdn-cgi/image/width=640,f=auto/https://860818f9.website-7p8.pages.dev/_app/immutable/assets/bg.90a72a2b.jpg▾
dark、
05/05/2023, 9:13 AMredux1997
05/05/2023, 1:35 PMthangnm
05/05/2023, 4:01 PMhappenator
05/06/2023, 12:19 AM500
errors in the browser, but Cloudflare Pages Functions logs show "successful" requests. How do I get the underlying error?
{
"outcome": "ok",
"scriptName": "pages-worker--1051688-production",
"exceptions": [],
"logs": [
{
"message": [
"Error: Unexpected Server Error"
],
"level": "error",
"timestamp": 1683332030573
}
],
"eventTimestamp": 1683332030459,
"event": {
"request": {
"url": "https://dd33ea81.cf-remix-65c.pages.dev/",
"method": "GET",
"headers": {
...
},
"cf": {
...
}
},
"response": {
"status": 500
}
},
"id": 0
}
albe
05/06/2023, 3:05 AM