Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-mammals-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/server": minor
---

Update srvx
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ The main server request handler invoked on every request.
Use this to integrate into your existing Node.js server.

This handler converts `http.IncomingMessage`/`http.ServerResponse` to `Request`/`Response`.
You can still access the Node.js versions via `req.node.req`/`req.node.res` in the hooks.
You can still access the Node.js versions via `req.runtime.node.req`/`req.runtime.node.res` in the hooks.

#### `server.handleWeb(req: Request)`

Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"debug": "^4.3.4",
"lodash.throttle": "^4.1.1",
"set-cookie-parser": "^2.7.1",
"srvx": "^0.2.8"
"srvx": "~0.8.2"
},
"devDependencies": {
"@types/debug": "^4.1.12",
Expand Down
13 changes: 8 additions & 5 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import http from 'node:http'
import {EventEmitter} from 'node:events'

import type {ServerRequest} from 'srvx/types'
import type {ServerRequest} from 'srvx'
import {toNodeHandler} from 'srvx/node'
import debug from 'debug'
import {EVENTS, ERRORS, REQUEST_METHODS, TUS_RESUMABLE, HEADERS} from '@tus/utils'
Expand Down Expand Up @@ -130,17 +130,20 @@ export class Server extends EventEmitter {
return this.handler(req)
}

private async handler(req: Request) {
private async handler(req: Request | ServerRequest) {
const context = this.createContext()
const headers = new Headers()

// Special case on the Node.js runtime,
// We handle gracefully request errors such as disconnects or timeouts.
// This is important to avoid memory leaks and ensure that the server can
// handle subsequent requests without issues.
if ('node' in req && req.node) {
const nodeReq = (req.node as {req: http.IncomingMessage}).req
nodeReq.once('error', () => {
if ((req as ServerRequest)?.runtime?.node) {
// biome-ignore lint/style/noNonNullAssertion: it's fine
const node = (req as ServerRequest).runtime?.node!
// @ts-expect-error backwards compatibility. srvx moved req.node to req.runtime.node.
req.node = node
node.req.once('error', () => {
context.abort()
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ServerRequest as Request} from 'srvx/types'
import type {ServerRequest as Request} from 'srvx'
import type {Locker, Upload} from '@tus/utils'

/**
Expand Down