Paul
Paul
Explore posts from servers
CDCloudflare Developers
Created by Paul on 6/27/2024 in #workers-help
Shared logic between NextJS app or duplicate the logic?
I naively thought I could share the logic from my nextjs app with my cloudflare workers but the environment variables is causing quite a bit of issues. Even when polyfilling with import * as process from 'node:process'; , whenever I use process.env, the nextjs app doesn't understand "node:process". Is it common to simply duplicate the logic for the cloudflare worker? Even my database calls requires a separate env and it's a bit too integrated. Is it common for folks to duplicate their code logic for CF workers or are people commonly able to reuse logic from their app? Is it common to declare something like globalThis.process = process (imported from node:process) when using cloudflare workers for nextjs and cloudflare worker compatability? I'm currently getting this error when I include import * as process from 'node:process'; in my nextjs app.
Module build failed: UnhandledSchemeError: Reading from "node:process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:process
Module build failed: UnhandledSchemeError: Reading from "node:process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:process
1 replies
CDCloudflare Developers
Created by Paul on 6/26/2024 in #workers-help
How to maintain WebSocket client connections in Durable Object?
1) Would it be the correct understanding that in order to use the Durable Objects Hibernation API, I need to extends the DurableObject class? 2) If so, how can I delete a certain clientId on close? In the examples, it doesn't extend the DurableObject class so the handleWebsocketSession method is able to set listeners to delete clientConnectionIds. However, when extending the durableObject class, the webSocketClose and webSocketError methods handle the closing of the client, so I'm not able to refer to the same clientId anymore.. See code below:
5 replies
CDCloudflare Developers
Created by Paul on 5/30/2024 in #workers-help
Queues taking 25 seconds to be consumed in development. Why?
In local development, when I have an api route that triggers a queue using hono, and the consumer simply console logs the message, for some reason it has a delay of 25 seconds before all the console logs come printing out. Any idea on why that is? I would have thought it would be instant...? Code is written with hono.js This is my producer:
app.get("/test", async c => {
const message = `Test message. Random number: ${Math.floor(Math.random() * 100)}`;
await c.env.WEBSITE_QUEUE.send({
body: message,
});

return c.json({ success: `Queued up this message: ${message}` });
});
app.get("/test", async c => {
const message = `Test message. Random number: ${Math.floor(Math.random() * 100)}`;
await c.env.WEBSITE_QUEUE.send({
body: message,
});

return c.json({ success: `Queued up this message: ${message}` });
});
This is my consumer that simply console.logs the message
export default {
fetch: app.fetch,
async queue(batch: MessageBatch<{ body: string }>, env: Environment) {
for (const message of batch.messages) {
console.log(
`Consuming message: ${JSON.stringify(message.body, null, 2)}`
);
}
},
};
export default {
fetch: app.fetch,
async queue(batch: MessageBatch<{ body: string }>, env: Environment) {
for (const message of batch.messages) {
console.log(
`Consuming message: ${JSON.stringify(message.body, null, 2)}`
);
}
},
};
2 replies