stukennedy
stukennedy
CDCloudflare Developers
Created by stukennedy on 10/18/2023 in #pages-help
Testing R2 from Pages
I'm running my Cloudflare Pages app locally using wrangler pages dev I have R2 instances for preview and production, but locally in dev it uses a version that wrangler is running in the .wrangler/state/v3/r2 folder. However, the other part of my app runs on a container, and I need to get hold of the R2 files on there to test functionality before deploying. I don't want to have to deploy my whole architecture to test it, so it'd be great if I could get my Pages app to talk to the preview remote R2 I noticed that wrangler dev has a --remote option, but Pages doesn't Any ideas how I get around this?
3 replies
CDCloudflare Developers
Created by stukennedy on 10/4/2023 in #pages-help
Worker Analytics Beta not working
There is a. beta feature that allows you to write custom analytics from Cloudflare Workers/pages I have enabled the analytics feature on the Pages overview. I click on setup and follow the instructions. I have created an entry in my toml [[analytics_engine_datasets]] binding = "ANALYTICS" I have added the binding to my env so my code can call it like this env.ANALYTICS.writeDataPoint({ blobs: ['signup', 'beta', 'failed'], indexes: [email, firstName, lastName], }); but I get an error when running the code locally as the local env.ANALYTICS resource being bound to doesn't seem to exist: TypeError: Cannot read properties of undefined (reading 'writeDataPoint') If I push it to preview it doesn't create the resource. I have manually gone into the function settings and set the binding on Analytics Engine bindings at the bottom of the page, still nothing. Any ideas?
7 replies
CDCloudflare Developers
Created by stukennedy on 9/26/2023 in #pages-help
Deploying Preview & Production
I have a Cloudflare Pages app. So far I've been deploying from the wrangler CLI straight to prod, but I want to transition to a pipeline that's driven from Github. Firstly: it seems if you started using the CLI you can't transition to using Github as a trigger for deployment. Secondly: if you do setup a trigger using Github pushes it doesn't sync the static assets and the build fails Is this correct? I've also been looking at using Github Actions, but I can't see a way to differentiate between preview and prod. I want my merges to mast to go to prod and any other branches to trigger a preview build. Please help, big project going properly live soon and the directors are already demoing the prod environment so I don't want to mess this up.
2 replies
CDCloudflare Developers
Created by stukennedy on 3/10/2023 in #pages-help
Intermittent problem routing in local dev
new to the channel ... I've got a full-stack HTMX JAMstack webapp running on Cloudflare Pages with functions and static, been handling auth etc. I needed to write a middleware to check the auth but I've noticed sometimes the router doesn't navigate to a sub-route and keeps navigating to the parent. It was happening with one page, and now it's happening with all of them, with no code changes. (this is on local dev) I'm logging out the request URL in the middleware and it's trying to get the parent page before I do anything, so it's definitely not my code. any ideas?
import { parseToken } from '@lib/token';

export const authentication: PagesFunction = async (context) => {
console.log('middleware', context.request.url);
if (parseToken(context.request)) {
return await context.next();
} else {
console.error('redirect');
const url = new URL(context.request.url);
return Response.redirect(url.origin, 301);
}
};

export const onRequest = [authentication];
import { parseToken } from '@lib/token';

export const authentication: PagesFunction = async (context) => {
console.log('middleware', context.request.url);
if (parseToken(context.request)) {
return await context.next();
} else {
console.error('redirect');
const url = new URL(context.request.url);
return Response.redirect(url.origin, 301);
}
};

export const onRequest = [authentication];
This is a _middleware.ts file inside my functions/dash/ folder (I had to put it in the subfolder as a _middleware in root folder also gets fire when getting static files, which is a pain) Anyway: when I try to navigate to URL http://127.0.0.1:3000/dash/products it logs out middleware http://127.0.0.1:3000/dash ... it works fine when published to Cloudflare
3 replies