bateswebtech
bateswebtech
CDCloudflare Developers
Created by bateswebtech on 10/22/2024 in #workers-help
Worker CLI deployment error
Hi, I was wondering if someone could assist me? I'm getting this error when deploying from the CLI. binding DB of type d1 failed to generate. Please try again later or contact support. [code: 10021]
4 replies
CDCloudflare Developers
Created by bateswebtech on 10/7/2024 in #pages-help
Getting a 500 internal server error
Today, we deployed new code and encountered a 500 error upon viewing the site. Even after reverting the commits, the error persisted following deployment. Ultimately, manually rolling back the deployment to an older commit from the pages dashboard brought the site back up, but as of now we are not able to push new code out.
8 replies
CDCloudflare Developers
Created by bateswebtech on 8/16/2023 in #workers-help
[Question] Is there a better way to run multiple workers with service bindings?
I am working on an app with around 10 workers all connected through service bindings with one acting as a "gateway". We used to use Miniflare 2 which allowed them to be sort of nested and we could run just the gateway which would automatically bind all the services. However, now that we have migrated to wrangler 3 we have to run each service individually and it's kind of a pain and a little bit chaotic. I'm currently using this package to run all of them at once https://github.com/mysticatea/npm-run-all I noticed in the docs for service bindings, they say that you should run each one separately. Just wanted to ask if anyone from the community has a similar use-case and other ways of doing this?
1 replies
CDCloudflare Developers
Created by bateswebtech on 8/16/2023 in #workers-help
[ERROR] Could not resolve "node:buffer"
Hello, I'm having some issues with building my worker using:
compatibility_flags = [ "nodejs_compat" ]
compatibility_flags = [ "nodejs_compat" ]
I'm using a PNPM monorepo and the import i'm using is as follows:
import { Buffer } from 'node:buffer'
import { Buffer } from 'node:buffer'
I have everything running and working in dev mode, however when I go to build the worker I get the following error:
> node ./build.js

[ERROR] Could not resolve "node:buffer"

src/index.ts:1:23:
1 │ import { Buffer } from 'node:buffer'
~~~~~~~~~~~~~

The package "node:buffer" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
> node ./build.js

[ERROR] Could not resolve "node:buffer"

src/index.ts:1:23:
1 │ import { Buffer } from 'node:buffer'
~~~~~~~~~~~~~

The package "node:buffer" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
here is my build.js file with esbuild
import { build } from 'esbuild'

try {
await build({
entryPoints: ['./src/index.ts'],
bundle: true,
outdir: './dist/',
sourcemap: true,
minify: true,
conditions: ['worker', 'browser'],
outExtension: { '.js': '.mjs' },
format: 'esm',
target: 'esnext',
plugins: [
]
})
} catch (err) {
process.exitCode = 1
}
import { build } from 'esbuild'

try {
await build({
entryPoints: ['./src/index.ts'],
bundle: true,
outdir: './dist/',
sourcemap: true,
minify: true,
conditions: ['worker', 'browser'],
outExtension: { '.js': '.mjs' },
format: 'esm',
target: 'esnext',
plugins: [
]
})
} catch (err) {
process.exitCode = 1
}
4 replies
CDCloudflare Developers
Created by bateswebtech on 6/23/2023 in #workers-help
Is it possible to share env variables among workers?
I have quite a few workers connected via service bindings and some of them have some env vars in common. I guess what i'm looking for would be like global variables accessible to all workers published on the account.
1 replies
CDCloudflare Developers
Created by bateswebtech on 6/10/2023 in #workers-help
Deployment error when using [placement] mode="smart"
Hello! I am attempting to deploy a worker that has a D1 database, and a Service binding. In my wrangler.toml config I have put it into the placement smart mode. [placement] mode="smart" I am getting an error which looks like my account has triggers and placement configured. error: workers.api.error.placement_and_triggers_configured [code: 100150] I have confirmed that I do not in fact have any triggers configured on the worker so I think this might be a bug. It seems like this user had a similar issue https://discord.com/channels/595317990191398933/1111627637912244254/1111750799266164868 but it looks like it was (potentially) resolved. @mhart Any help would be much appreciated!
11 replies
CDCloudflare Developers
Created by bateswebtech on 4/10/2023 in #workers-help
Trying to make a simple cache using a cloudflare worker with hono.
I was wondering if anyone could assist me with what I thought was going to be a simple usage of the cache api. My issue is that I cannot seem to get the cache to store the body properly... The cache key is getting stored and properly invalidated after 10 seconds but the body is always an empty object when the cache is matched.
app.get('/events', async (c) => {
try {
const cacheUrl = c.req.url
const cache = caches.default

// Check if our response is already in the cache
let response = await cache.match(cacheUrl)
console.log('body', JSON.stringify(response?.body))

if (!response) {
const { email } = c.req.query()
const config = getConfig(c.env)
const events = await findEvents(email, config)

response = new Response(JSON.stringify({ data: events }))
response.headers.append('Cache-Control', 's-maxage=10')

c.executionCtx.waitUntil(cache.put(cacheUrl, response.clone()))

return c.json({
data: events
})
} else {
console.log(`cache hit for ${cacheUrl}`)
}

return response
} catch (err: Error | any) {
return c.json(
{
error: {
message: err.message
}
},
500
)
}
})
app.get('/events', async (c) => {
try {
const cacheUrl = c.req.url
const cache = caches.default

// Check if our response is already in the cache
let response = await cache.match(cacheUrl)
console.log('body', JSON.stringify(response?.body))

if (!response) {
const { email } = c.req.query()
const config = getConfig(c.env)
const events = await findEvents(email, config)

response = new Response(JSON.stringify({ data: events }))
response.headers.append('Cache-Control', 's-maxage=10')

c.executionCtx.waitUntil(cache.put(cacheUrl, response.clone()))

return c.json({
data: events
})
} else {
console.log(`cache hit for ${cacheUrl}`)
}

return response
} catch (err: Error | any) {
return c.json(
{
error: {
message: err.message
}
},
500
)
}
})
The logs are showing up as this with an empty body when hitting the cache.
{
"outcome": "ok",
"scriptName": "some script name",
"exceptions": [],
"logs": [
{
"message": [
"body",
"{}"
],
"level": "log",
"timestamp": 1681117743889
},
{
"message": [
"cache hit for https://someurl/[email protected]"
],
"level": "log",
"timestamp": 1681117743889
}
],
"eventTimestamp": 1681117743883,
"event": {
"request": {
"url": "some url",
"method": "GET",
"headers": {
"content-type": "application/json"
}
},
"response": {
"status": 500
}
},
"id": 27
}
{
"outcome": "ok",
"scriptName": "some script name",
"exceptions": [],
"logs": [
{
"message": [
"body",
"{}"
],
"level": "log",
"timestamp": 1681117743889
},
{
"message": [
"cache hit for https://someurl/[email protected]"
],
"level": "log",
"timestamp": 1681117743889
}
],
"eventTimestamp": 1681117743883,
"event": {
"request": {
"url": "some url",
"method": "GET",
"headers": {
"content-type": "application/json"
}
},
"response": {
"status": 500
}
},
"id": 27
}
5 replies