MyFriendliestFace
MyFriendliestFace
CDCloudflare Developers
Created by MyFriendliestFace on 4/25/2024 in #pages-help
entry level issue with react & functions - no links created
Hello, I just installed the react app using cloudflare documentation, and in my pages I just have out of the box react setup. I added functions folder and 2 “hello world” type functions that say calls.js and dashboard.js. Functions say: export async function onRequest(context) { return new Response (“Hello, it’s Calls page.”) } And similarly the other page also. My homepage (App.js) is also hello world message. When I try to load in my localhost:3000/calls nothing happens with either link, no error but also no activity. Per documentation it sounds like just functions folder in root should do the trick and enable these routes. What am I doing wrong? I just want basic routing functionality and some links on homepage would be great. Any insight is highly appreciated. I am afraid to use any packages like react-router since I see lots of folks complaining CF pages doesn’t support it.
1 replies
CDCloudflare Developers
Created by MyFriendliestFace on 1/30/2024 in #workers-help
How to successfully initialize the R2 object?
Hello all, first off, I apologize for a potentially dumb question. I am not able to initialize an R2 object and test it out correctly. I have the R2 object code taken from the documentation, which is shown below. I am trying to call this object from a different module and execute it, but its just erroring out whatever i try. here is my latest attempt, getting errors about that I didn't initialize the object properly or that I didn't have the right formats. I appreciate anyone who can give me pointers, nothing is available on google. //////////////////////////////////////////////////// my attempt at creating sample data in r2 /////////////////////////////////////////////////// // r2PushData.js import r2Object from './objectR2'; // Create an instance of Env const env = { R2_BUCKET: R2Bucket, AUTH_KEY_SECRET: 'hidden-from-chat', }; // Create an instance of R2Bucket env.R2_BUCKET = new R2Bucket; // Use the exported fetch function to push data to the R2 bucket const requestData = "Test body 'first upload of data to r2'"; const request = new Request('https://hiddenurl.com/test', { method: 'PUT', body: requestData, headers: { 'X-Custom-Auth-Key': env.AUTH_KEY_SECRET, }, }); r2Object.fetch(request, env, {}).then((response) => { console.log(response.status); console.log(response.statusText); }); /////////////////////////////////////// This is the object below, no errors with the file. ////////////////////////////////////// // objectR2.ts I dont have space to include all code, but it is this object from this support video https://www.youtube.com/watch?v=VEATzKttaMI&t=331s and also this article (if you want to copy/paste code) https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
5 replies