Srd
05/18/2023, 8:31 AMNeiki
05/18/2023, 9:36 AMhttps://cdn.discordapp.com/attachments/779390076219686943/1108663705291468841/image.png▾
https://cdn.discordapp.com/attachments/779390076219686943/1108663742893400074/image.png▾
https://cdn.discordapp.com/attachments/779390076219686943/1108650363319504926/image.png▾
https://cdn.discordapp.com/attachments/779390076219686943/1108650363604701224/image.png▾
https://cdn.discordapp.com/attachments/1108689633295999007/1108690021936017418/image.png▾
Gamengineer314
05/18/2023, 2:38 PMhttps://cdn.discordapp.com/attachments/1108765496087679038/1108765634566836305/image.png▾
https://cdn.discordapp.com/attachments/1108765496087679038/1108765634885591120/image.png▾
Jerasaurus
05/18/2023, 11:49 PMworkerd/server/server.c++:2347: error: Uncaught exception: kj/async-io-win32.c++:385: failed: WSARecv(): #64 The specified network name is no longer available.
stack: 7ff680e88950 0 0 0 0
doesnt seem like its a workers issue since stack overflow wasnt helpful but also I may be doing this all wrong
(exact code https://pastebin.com/dT4G1xnE)attfarhan
05/19/2023, 7:28 AMconst statusCode = 302
const resp = new Response(null, {
status: statusCode,
headers: new Headers({ Location: EXPERIMENTATION_URL }),
})
return resp
For the control group, we send the user through to the original site they requested:
let resp = await fetch(request)
resp = new Response(resp.body, resp)
resp.headers.append("Set-Cookie", newCookie) // only if they have no cookie yet
return resp
However, for some reason, in about 50% of the cases that we hit the case where the user has no analytics cookie yet, and is in the control group, the request in the Worker logs shows up as canceled. A few seconds after the canceled request, there is usually a successful request, which seems to be a retry, but this results in the user being assigned to a variant group.
This case is the last case to get handled in the Worker code. However, I am a bit baffled as this is the only case that fails.
Is there any way to check why these requests are being canceled? Or are there any common reasons why requests get canceled, especially if the requests only get canceled in a specific code path ?Slotherman
05/19/2023, 7:51 AMWorkers Unbound has not yet been enabled for this account. (Code: 10075)
I don't have any other variables yet, so I assume this would be allowed. I can't seem to find much information on this.
Does anybody know how to resolve it other than by credit card? 🙂F0rce
05/19/2023, 9:52 AM8787
. Now each start of the environment seems to have a random port (at the time of trying its 64278
). As the Port is not always the same and a new restart creates a new port, it is a pain to update the development frontend env or my api testing client (insomnia) to always be at the correct port.
Is this a bug on macOS or is there a way to force the port to be at 8787 ?
Thanks in advance,
Davidttraenkler
05/19/2023, 11:25 AMsdan
05/19/2023, 11:47 AMhttps://cdn.discordapp.com/attachments/1109085025988771890/1109085026248835112/Screenshot_2023-05-19_at_4.46.49_AM.png▾
super_pispis
05/19/2023, 2:02 PMError: Script startup exceeded CPU time limit. [code: 10021] when using static import
when deploying. It is resolved when I use dynamic import (import('...
), but dynamic import apparently doesn't work with wasm. Any suggestions?Bhone M Min
05/19/2023, 2:29 PMhttps://cdn.discordapp.com/attachments/1109125738348675092/1109125739124629554/image.png▾
https://cdn.discordapp.com/attachments/1109125738348675092/1109125739606982697/image.png▾
TheStuntback46
05/19/2023, 4:08 PMOperator
05/19/2023, 5:44 PMasync function handleSitemap() {
const sitemapUrl = 'https://tempsite.com/sitemap.xml'
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.9'
}
let response = await fetch(sitemapUrl, {method: 'GET', headers: headers})
console.log(response.body)
if (!response.ok) {
throw new Error('No response!')
}
let data = await response.text()
const contentType = response.headers.get('content-type')
// Replace 'tempsite.com' with 'mysite.com'
data = data.replace(/tempsite\.com/g, 'mysite.com')
return new Response(data, {
headers: {
'content-type': contentType
}
})
}
https://cdn.discordapp.com/attachments/1109174734966493274/1109174735109111820/image.png▾
embed
05/20/2023, 4:42 AMMatt
05/20/2023, 7:14 AMnexpid
05/20/2023, 8:09 AMhttps://cdn.discordapp.com/attachments/1109392374318243952/1109392374490222612/image.png▾
https://cdn.discordapp.com/attachments/1109392374318243952/1109392374779609148/image.png▾
subhendupsingh
05/20/2023, 11:05 AMworkerd/jsg/util.c++:276: error: e = kj/compat/tls.c++:215: failed: TLS peer's certificate is not trusted; reason = unable to get local issuer certificate
stack: 7ff6229c8a6f 7ff622a0c9dd 0 0 0 0 0 0 0 0 0 0 0 0 7ff6229d6234; sentryErrorContext = jsgInternalError
Even when i explicitly pass the --local-protocol http
npx wrangler dev src/index.ts --local-protocol http
Bamboo
05/20/2023, 11:16 AMconst 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.D I
05/20/2023, 4:05 PMhttps://cdn.discordapp.com/attachments/1109512260323397652/1109512261187408002/image.png▾
daver
05/20/2023, 8:11 PMUnknown Event - Exceeded CPU Limit
errors without doing very much, e.g. just deserializing the message batch exactly as in the worker-rs
example for queues. This happen with a single message. I tried setting usage_model=unbound
in wrangler.toml and I see it picked up in the UI, but the error persists. Am I missing something obvious?happenator
05/20/2023, 8:40 PMgoogleapis
, which has a require('http2')
while http2
isn't available in the runtime. That might be fine -- I think I can pass runtime options to avoid using it. I just need to find a way to get esbuild
to ignore the missing dependancy.ItsWendell
05/20/2023, 10:09 PM/public/some-temp-image.png
? We use getAssetFromKV:
return await getAssetFromKV(
{
request: ctx.req.raw,
waitUntil: ctx.executionCtx.waitUntil.bind(ctx.executionCtx),
},
{
ASSET_NAMESPACE: ctx.env.__STATIC_CONTENT,
mapRequestToAsset: (req) => {
const url = new URL(req.url);
url.pathname = url.pathname.replace(/^\/public/, "");
return new Request(url.toString(), req);
},
},
);
} catch (e) {
if (e instanceof Error) {
console.error(e);
if ("status" in e) {
if (e.status === 404) {
return ctx.notFound();
}
}
}
throw e;
}
Can we skip workers sites from adding these hashes?D I
05/20/2023, 10:51 PMsideshot
05/21/2023, 2:10 AMSakuraPY
05/21/2023, 4:25 AM0xAsimetriq
05/21/2023, 1:06 PMsideshot
05/21/2023, 4:15 PMFelix || TM9657
05/21/2023, 6:16 PMjs
import {
AICache,
authorize,
CorsResponse,
OpenAIStreamHandler,
} from "@tm9657/backend-worker";
import GPT3Tokenizer from "gpt3-tokenizer";
import { Configuration, OpenAIApi } from "openai";
export interface Env {
DATABASE_URL: string;
OPENAI_KEY: string;
}
type AIRequestBody = {
prompt: string;
system?: string;
top_p?: number;
frequency_penalty?: number;
max_tokens?: number;
};
let cache: AICache | null = null;
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const auth = await authorize(request);
if (!auth) return new CorsResponse("Unauthorized", 401).finalize(request);
const body: AIRequestBody = await request.json();
if (!body || !body?.prompt)
return new CorsResponse("Bad Request", 400).finalize(request);
if (!cache) cache = new AICache();
cache.init(env.DATABASE_URL);
let openai: OpenAIApi = new OpenAIApi(
new Configuration({
apiKey: env.OPENAI_KEY,
})
);
if (!openai)
return new CorsResponse("Internal Server Error", 500).finalize(request);
const usage = await cache.getUsage(auth.sub);
if (!usage.getHardLimit())
return new CorsResponse(
"Monthly API limit hit, please upgrade your subscription!",
429
).finalize(request);
const tokenizer = new GPT3Tokenizer({ type: "gpt3" });
const { readable, writable } = new TransformStream();
const openAIRequest = await openai.createChatCompletion(
{
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: body.system || "" },
{ role: "user", content: `${body.prompt}` },
],
top_p: body.top_p || 0.05,
max_tokens:
4096 - tokenizer.encode(`${body.prompt} ${body.system}`).bpe.length,
user: auth.sub,
frequency_penalty: body.frequency_penalty || 1.0,
stream: true,
},
{ responseType: "stream" }
);
const writableStream = writable.getWriter();
let total = "";
const handler = new OpenAIStreamHandler(
openAIRequest,
async (message) => {
total += message;
await writableStream.write({ total, message });
},
async () => {
await writableStream.close();
await cache?.updateUsage(
auth.sub,
"chatGPT",
tokenizer.encode(`${body.prompt} ${body.system} ${total}`).bpe.length
);
}
).promise();
return new CorsResponse(readable).finalize(request);
},
};
sideshot
05/21/2023, 7:43 PM// rate-limiter.js
export class APIRequestCounter {}
}
// index.js
import { APIRequestCounter } from './rate-limiter.js';
export default {
async fetch(request, env, ctx) {
}
}
TRY 1: WRANGLER.toml
[durable_objects]
bindings = [{name = "API_RATE_LIMITER", class_name = "APIRequestCounter", script_name = "rate-limiter.js"}]
TRY 2: WRANGLER
[durable_objects]
bindings = [{name = "API_RATE_LIMITER", class_name = "APIRequestCounter", script_name = "rate-limiter"}]
TRY 3: WRANGLER
[durable_objects]
bindings = [{name = "API_RATE_LIMITER", class_name = "APIRequestCounter", script_name = "./rate-limiter.js"}]
shrirambalaji
05/21/2023, 11:35 PMts
export default {
async fetch(request: {
url: string | URL; headers: { get: (arg0: string) => string }
}, env: any, ctx: any) {
try {
const subdomain = request.headers.get('host').split('.')[0];
// ... map subdomain to id
const destinationURL = new URL(`http://localhost:3001/${id}`);
const response = await fetch(destinationURL);
const proxyResponse = new Response(response.body, { headers: response.headers, status: response.status, statusText: response.statusText})
return proxyResponse
} catch (error) {
return new Response(null, { status: 404, statusText: "Oops can't find that page" });
}
},
};
What am I missing here?
https://cdn.discordapp.com/attachments/1109987865154310245/1109987865603084288/image.png▾