H
Hono•2mo ago
Paul

Can't integrate hono with tus server

Anyone here used Tus: @tus/server I'm having difficulty using hono with it. Here are the different examples of using it with other providers: https://github.com/tus/tus-node-server/tree/main/packages/server#example-integrate-tus-into-express here is what I tried:
const tusServer = new Server({
path: '/uploads',
datastore: new FileStore({
directory: '/Users/paul/development/src/github/[project]/apps/hono/tmp',
}),
});

app.all('/api/dam/uploads', (c) => {
return tusServer.handle(c.req, c.res);
})
const tusServer = new Server({
path: '/uploads',
datastore: new FileStore({
directory: '/Users/paul/development/src/github/[project]/apps/hono/tmp',
}),
});

app.all('/api/dam/uploads', (c) => {
return tusServer.handle(c.req, c.res);
})
I keep getting: TypeError: req.on is not a function (probably from the tus server)
3 Replies
ambergristle
ambergristle•2mo ago
so a core problem here is that hono has a different request architecture tus (and express) expect req to be IncomingMessage, while hono gives you access to Context and the Request i suspect this is because hono strives to be cross-runtime compatible. e.g., IncomingMessage may not be available in cloudflare something like this might work: https://stackoverflow.com/questions/67049890/how-can-i-turn-a-node-js-http-incomingmessage-into-a-fetch-request-object but you'd need to go the other way
Paul
PaulOP•2mo ago
Thanks for the reply. Appreciate it!
For now I have tus as a separate service, but when I go into prod I will circle back and correct based on your link.
Martin
Martin•4w ago
I made a custom implementation here: https://github.com/Cap-go/hono-r2-tus-uploader and did open a issue in TUS to get support: https://github.com/tus/tus-node-server/issues/715 Let's up the issue then i got visible for TUS team 🙂
GitHub
GitHub - Cap-go/hono-r2-tus-uploader: An implementation of the TUS ...
An implementation of the TUS server protocol for resumable uploads - Cap-go/hono-r2-tus-uploader
GitHub
Support Hono · Issue #715 · tus/tus-node-server
Initial checklist I understand this is a feature request and questions should be posted in the Community Forum I searched issues and couldn’t find anything (or linked relevant results below) Proble...

Did you find this page helpful?