two-stroke 8.0.25 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/REVIEW.md +8 -0
- package/oxlint.config.mjs +1 -0
- package/package.json +3 -3
- package/src/index.ts +9 -4
package/REVIEW.md
ADDED
package/oxlint.config.mjs
CHANGED
|
@@ -54,6 +54,7 @@ export default defineConfig({
|
|
|
54
54
|
"no-continue": "off",
|
|
55
55
|
"init-declarations": "off",
|
|
56
56
|
"vitest/prefer-to-be-truthy": "off",
|
|
57
|
+
"vitest/prefer-to-be-falsy": "off",
|
|
57
58
|
"vitest/prefer-expect-assertions": "off",
|
|
58
59
|
"vitest/prefer-importing-vitest-globals": "off",
|
|
59
60
|
"vitest/no-importing-vitest-globals": "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "two-stroke",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Simple Cloudflare Worker framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"zod": "^4.4.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@cloudflare/vitest-pool-workers": "^0.
|
|
33
|
+
"@cloudflare/vitest-pool-workers": "^0.22.0",
|
|
34
34
|
"knip": "^6.31.0",
|
|
35
|
-
"oxfmt": "^0.
|
|
35
|
+
"oxfmt": "^0.65.0",
|
|
36
36
|
"oxlint": "^1.76.0",
|
|
37
37
|
"oxlint-tsgolint": "^7.0.2001",
|
|
38
38
|
"vitest": "^4.1.10"
|
package/src/index.ts
CHANGED
|
@@ -72,9 +72,12 @@ export function twoStroke<T>(
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
const { pathname } = new URL(req.url);
|
|
75
|
+
// HEAD is served by the GET route, with the body discarded.
|
|
76
|
+
const isHead = req.method === "HEAD";
|
|
77
|
+
const method = isHead ? "GET" : req.method;
|
|
75
78
|
let response;
|
|
76
79
|
for (const route of routes) {
|
|
77
|
-
if (
|
|
80
|
+
if (method === route.method && route.matcher.test(pathname)) {
|
|
78
81
|
const params = Object.fromEntries(
|
|
79
82
|
Object.entries(pathname.match(route.matcher)?.groups ?? {}).map(([k, v]) => [
|
|
80
83
|
k,
|
|
@@ -199,9 +202,11 @@ export function twoStroke<T>(
|
|
|
199
202
|
});
|
|
200
203
|
|
|
201
204
|
return new Response(
|
|
202
|
-
|
|
203
|
-
?
|
|
204
|
-
:
|
|
205
|
+
isHead
|
|
206
|
+
? null
|
|
207
|
+
: responseWithHeaders.headers.get("Content-Type") === "application/json"
|
|
208
|
+
? JSON.stringify(response.body)
|
|
209
|
+
: response.body,
|
|
205
210
|
responseWithHeaders,
|
|
206
211
|
);
|
|
207
212
|
}
|