H
Hono3w 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)
2 Replies
ambergristle
ambergristle3w 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
PaulOP3w 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.

Did you find this page helpful?