Skip to content

Commit 51419da

Browse files
authored
Refactor server to run in all (Node.js compatible) runtimes and meta frameworks (#710)
Refactor the request handlers and hooks to be based on `Request` (from the fetch API) instead of `http.IncomingMessage`/`http.ServerResponse` (which are Node.js specific) as we can turn the Node.js ones into `Request`/`Response` but not the other way around. That means we can have a `handle(req, res)` method for Node.js servers and a `handleWeb(req)` for other runtimes and meta-frameworks (such as Next.js React Router, SvelteKit, etc) which both use the same core logic.
1 parent ba571db commit 51419da

28 files changed

+1024
-931
lines changed

.changeset/polite-bikes-train.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@tus/server": major
3+
---
4+
5+
- Introduce `handleWeb(req: Request)` to integrate into meta frameworks
6+
(such as Next.js, Nuxt, React Router, SvelteKit, etc) and other Node.js compatible runtime environments.
7+
- All events and hooks now emit `Request`/`Response` instead of `http.IncomingMessage`/`http.ServerResponse`.
8+
- The function version of the options `maxSize`, `generateUrl`, `getFileIdFromRequest`, `namingFunction`, `locker`
9+
also now use `Request`/`Response`.
10+
- Your `onUploadCreate` and `onUploadFinish` hooks no longer need to return the response object.
11+
- If you want to change the metadata in `onUploadCreate` you can return `Promise<{ metadata: Record<string, string> }>`.
12+
This will will internally merge the existing metadata with the new metadata.
13+
- `onUploadFinish` can return `Promise<{ status_code?: number headers?: Record<string, string | number> body?: string }>`

biome.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"enabled": true
55
},
66
"files": {
7-
"ignore": ["./**/dist/**/*"]
7+
"ignore": [".git", "node_modules", "./**/dist/**/*"]
88
},
99
"linter": {
1010
"enabled": true,
1111
"rules": {
1212
"recommended": true,
1313
"style": {
1414
"noParameterAssign": "off"
15+
},
16+
"performance": {
17+
"noDelete": "off"
1518
}
1619
}
1720
},

package-lock.json

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)