mau
mau
Explore posts from servers
CDCloudflare Developers
Created by Jacob on 8/7/2024 in #workers-help
KV Namespace methods break when passed through constructor
I have sent you code in dm
4 replies
CDCloudflare Developers
Created by Jacob on 8/7/2024 in #workers-help
KV Namespace methods break when passed through constructor
I didn’t use cloudflare cache…I can share you repo where I implemented this.
4 replies
HHono
Created by Blankeos on 6/22/2024 in #help
Have you guys ever gotten websockets to work on Hono + `@hono/vite-dev-server` plugin?
I finally made a decision to use partykit... i am exploring and trying to see if i like the abstraction or not.
5 replies
HHono
Created by Blankeos on 6/22/2024 in #help
Have you guys ever gotten websockets to work on Hono + `@hono/vite-dev-server` plugin?
If i add http routes and i want to set cors etc it starts giving me error
5 replies
HHono
Created by Blankeos on 6/22/2024 in #help
Have you guys ever gotten websockets to work on Hono + `@hono/vite-dev-server` plugin?
here is sample code...
app.get(
'connect',
upgradeWebSocket((c) => {
return {
onMessage(event, ws) {
// console.log(`Message from client: ${event.data}`);
// let data = { ...event.data, event: 'send' };
console.log(event);
ws.send(event.data);
},
onClose: () => {
console.log('Connection closed');
},
onOpen: (e) => {
console.log('open', e);
},
};
})
);
app.get(
'connect',
upgradeWebSocket((c) => {
return {
onMessage(event, ws) {
// console.log(`Message from client: ${event.data}`);
// let data = { ...event.data, event: 'send' };
console.log(event);
ws.send(event.data);
},
onClose: () => {
console.log('Connection closed');
},
onOpen: (e) => {
console.log('open', e);
},
};
})
);
5 replies
HHono
Created by Blankeos on 6/22/2024 in #help
Have you guys ever gotten websockets to work on Hono + `@hono/vite-dev-server` plugin?
i was able to get it to work but the issue was facing was with headers.
5 replies
HHono
Created by Paul on 6/26/2024 in #help
Can the queue only be defined in the root?
Yes, i also did with root and i wasn't able to think of any other way myself.
import { Hono } from 'hono';

type Environment = {
readonly ERROR_QUEUE: Queue<any>;
};

const queue = new Hono<{
Bindings: Environment;
}>();

queue.get('/', async (c) => {
await c.env.ERROR_QUEUE.send({ progressId: 1 });
return c.json({ success: true });
});

export default queue;

export default {
fetch: app.fetch,
async queue(batch: MessageBatch<any>, env: any) {
for (const message of batch.messages) {
queueProcessor(message);
}
},
};

function queueProcessor(message: any) {
const { body, attempts } = message;
if (Math.random() < 0.5) {
switch (body?.event) {
case 'start-quiz':
console.log('data', body, 'attempts', attempts);
break;
default:
console.log('data', body, 'attempts', attempts);
break;
}
} else {
throw new Error('Failed!');
}
}
import { Hono } from 'hono';

type Environment = {
readonly ERROR_QUEUE: Queue<any>;
};

const queue = new Hono<{
Bindings: Environment;
}>();

queue.get('/', async (c) => {
await c.env.ERROR_QUEUE.send({ progressId: 1 });
return c.json({ success: true });
});

export default queue;

export default {
fetch: app.fetch,
async queue(batch: MessageBatch<any>, env: any) {
for (const message of batch.messages) {
queueProcessor(message);
}
},
};

function queueProcessor(message: any) {
const { body, attempts } = message;
if (Math.random() < 0.5) {
switch (body?.event) {
case 'start-quiz':
console.log('data', body, 'attempts', attempts);
break;
default:
console.log('data', body, 'attempts', attempts);
break;
}
} else {
throw new Error('Failed!');
}
}
2 replies