Bamboo
Bamboo
CDCloudflare Developers
Created by Bamboo on 6/17/2024 in #workers-help
Setup Workerd in local dev for sveltekit project
So up until now, i was developing on node and deploying it, but some time I get error after deployment like yesterday, I get "node.buffer not available". So I decided to use workerd in the local dev also. But how to setup? I found docs, suggesting use wrangler for specific worker developement. But how to use and setup sveltekit project on workerd? How?
2 replies
CDCloudflare Developers
Created by Bamboo on 4/17/2024 in #workers-help
Why use tail workers over producer worker can be used to send all the logs itself?
I want to collect error logs in my app and I came across tail worker. And I couldn't understand the logic behind its existence. Why would I use tail workers when I can just send all the errors and logs at the end of the request. I can use try catch block to capture all the errors and also save the tail workers invoke request costs which is same as workers? Do it provide any added benefits that I couldn't get?
4 replies
CDCloudflare Developers
Created by Bamboo on 4/17/2024 in #workers-help
sveltekit app deployed on cloudflare. will it become slow as project size increases?
When sveltekit runs build command, it outputs _workers.js file containing all the server code in one file. Mine at present is 980kb. And i expect it to grow as i add more code. 1. Does the request response become slow as the size increases as this huge script has to load on every request. 2. And i saw in docs the workers size limit is 1mb for free tier. Is it the same for page functions?
4 replies
CDCloudflare Developers
Created by Bamboo on 11/26/2023 in #workers-help
How to secure workers from abuse?
I want to build my whole website using serverless architecture which is mostly workers and d1. Most of the content on my website can be accessed by users without any authentication/signin. So what steps i should take to not get billed for misuse of my api endpoints? Are there any docs or resources that can guide me? Or are there any cloudflare options to protect my endpoints?
2 replies
CDCloudflare Developers
Created by Bamboo on 11/10/2023 in #workers-help
Building search suggestions for a website
I want to build a search engine for a small website. Agolia or mellisearch would do the work, but they are over my requirements in terms of price and features. A simple search suggestions would do the work for me. Like building a API that searches the d1 database for given query and return results, but I think this is expensive as it has to go through whole database everytime. And indexes help but i came to know that indexed don't auto update when more data is added to database. So it there any other way to build this simple in terms of price and code, other than using third party solutions like algolia or builiding an api that queries whole d1 database everytime for each letter of search word? I also came to know about Full Text Search?
5 replies
CDCloudflare Developers
Created by Bamboo on 5/20/2023 in #workers-help
CORS issue even when CORS header are added
My workers script with d1 binding, and '/api/view/customers_data' on GET request is succesful but sending POST request with body to '/api/add/customer' giving error Fetch request const response = await fetch( "https://xxxx.xxxxx.workers.dev/api/add/customer", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ id: xxx, cabin: xxxx, name: xxxx },) } ); // Workers Script export default { async fetch(request, env, ctx) { const corsHeaders = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*', 'Access-Control-Allow-Methods': 'GET, POST', }; const { pathname } = new URL(request.url); try { if (pathname === "/api/view/customers_data") { const results = await env.DB.prepare( "SELECT * FROM customers_data " ).all(); return new Response(JSON.stringify(results), { headers: corsHeaders, }); }else if (pathname === "/api/add/customer") { const body = await request.json(); const results = await env.DB.prepare( "INSERT INTO customers_data (cabin, name, email, phone, gender) VALUES(?1, ?2, ?3, ?4, ?5)" ).bind(body.cabin, body.name, body.email, body.phone, body.gender).run(); return new Response(JSON.stringify(results), { headers: corsHeaders, }); } } catch (e) { return Response.json(e); } }); } }; //Error Access to fetch at 'https://xxx.xxxx.workers.dev/api/add/customer' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
14 replies
CDCloudflare Developers
Created by Bamboo on 5/17/2023 in #workers-help
Workers request.body empty
I'm running a worker locally whose work is to return the request.body back, and I made a POST request with some body in application/json format, but in response I get {}, but request.cf is working perfectly, and on request.bodyUsed, I get false export default { async fetch(request, env, ctx) { const { pathname } = new URL(request.url); if (pathname === "/api/modify") { return Response.json(request.body); } } }
4 replies
CDCloudflare Developers
Created by Bamboo on 5/16/2023 in #workers-help
Workspace with separate billing?
How to manage billing for different websites based on usage? Like how a freelancer can bill his individual clients according to their usage of services? And how to view which services (like workers request, stream, images) a website is using individually like per website basis? Something like workspaces with its own billing and services listed?
2 replies
CDCloudflare Developers
Created by Bamboo on 5/11/2023 in #workers-help
Connecting to CockroachDB serverless using pg via workers
1. Created a npx wrangler init . 2. Then "npm install pg" and added the query code into index.js 3. then, npx wrangler dev, got compatibility errors, and got suggestions to add "node_compat = true", and I did, those errors disappeared 4. Then again ran "npx wrangler dev", got error ' could not resolve "pg-native" '. And this is where I'm struck. I ran same code in normal js and it worked, but I don't know why is it asking "pg-native", and also I tried to install it locally and globally, and it won't get installed. 5. What to do?
5 replies