Artifex
Artifex
HHono
Created by blurSkye πŸ‡΅πŸ‡ΈπŸ‰ on 6/7/2024 in #help
websocket issue
25 replies
HHono
Created by blurSkye πŸ‡΅πŸ‡ΈπŸ‰ on 6/7/2024 in #help
websocket issue
If you are doing it in bun maybe it's better to use the pubsub? Here is simple example.
app.get(
'pubsub',
upgradeWebSocket((c) => {
return {
onOpen(evt, ws) {
const raw = ws.raw as ServerWebSocket;
raw.subscribe('pubsub');
},
onMessage(evt, ws) {
const raw = ws.raw as ServerWebSocket;
console.log(raw.isSubscribed('pubsub'));
server.publish('pubsub', `Subscriber ${evt.data}`);
}
};
})
);

const server = serve({
port: process.env.PORT || 3000,
hostname: '0.0.0.0',
fetch: hono.fetch,
websocket
});

console.log(`Listening on ${server.hostname}:${server.port} πŸ”₯`);
app.get(
'pubsub',
upgradeWebSocket((c) => {
return {
onOpen(evt, ws) {
const raw = ws.raw as ServerWebSocket;
raw.subscribe('pubsub');
},
onMessage(evt, ws) {
const raw = ws.raw as ServerWebSocket;
console.log(raw.isSubscribed('pubsub'));
server.publish('pubsub', `Subscriber ${evt.data}`);
}
};
})
);

const server = serve({
port: process.env.PORT || 3000,
hostname: '0.0.0.0',
fetch: hono.fetch,
websocket
});

console.log(`Listening on ${server.hostname}:${server.port} πŸ”₯`);
25 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
just append the .get on new Hono()
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
well c.body.experimentId does not exist totally tho
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
u can append it before the basepath i think
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
u can also chain it so you get a better readability
statisticsRouter
.basePath('/:experimentId')
.use(canExperiment)
.get('/statistics', significanceMiddleware, significanceHandler)
.get('/chart-data', chartDataMiddleware, chartDataHandler)
.get('/currencies', currenciesHandler);
statisticsRouter
.basePath('/:experimentId')
.use(canExperiment)
.get('/statistics', significanceMiddleware, significanceHandler)
.get('/chart-data', chartDataMiddleware, chartDataHandler)
.get('/currencies', currenciesHandler);
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
might want to chain those later on for rpc
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
Are you not using rpc?
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
oh mybad
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
We are trying to help
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
well if you enable strict true, you will see those things does not exist in its context yet
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
for better typesafety wrap middleware in createMiddleware
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
idk why typescript is not shouting at you when you are accesing c.params('ex...') and c.body....
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
its all undefined here if you access this on middleware
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
let me recreate what you are trying to do lets see if we are on the same page
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
you can use the one later on as c.var['objname']
101 replies
HHono
Created by rubberduckies on 5/29/2024 in #help
middleware on a router level
in middleware you can also c.set() then call next()
101 replies
HHono
Created by Damian on 5/21/2024 in #help
Importing AppType to client defaults output to any types
Are you in a monorepo? composite: true is needed and moduleResolution to "node" so you can directly import the type
7 replies
HHono
Created by ! Gaetan Puleo on 5/26/2024 in #help
Hot reload not working? (BUN)
even not doing the vite config just a plain hono server break things for me
7 replies