-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: support HEAD, PATCH and OPTIONS http methods * feat: use GET without body as default HEAD handling * chore: remove console.log and update lint config * fix: update CI to use node 20,22 and windows * fix: collapse default HEAD entry in routes log
- Loading branch information
Showing
55 changed files
with
1,008 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marko/run": patch | ||
--- | ||
|
||
Support PATCH, OPTIONS and HEAD http methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/run/src/__tests__/fixtures/all-http-verbs/.marko-run/routes.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. | ||
Do NOT manually edit this file or your changes will be lost. | ||
*/ | ||
|
||
import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; | ||
import type * as Run from "@marko/run"; | ||
|
||
|
||
declare module "@marko/run" { | ||
interface AppData extends Run.DefineApp<{ | ||
routes: { | ||
"/": Routes["/"]; | ||
} | ||
}> {} | ||
} | ||
|
||
declare module "../src/routes/+handler" { | ||
namespace MarkoRun { | ||
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; | ||
export type Route = Run.Routes["/"]; | ||
export type Context = Run.MultiRouteContext<Route>; | ||
export type Handler = Run.HandlerLike<Route>; | ||
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ | ||
export const route: Run.HandlerTypeFn<Route>; | ||
} | ||
} | ||
|
||
declare module "../src/routes/+page.marko" { | ||
namespace MarkoRun { | ||
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; | ||
export type Route = Run.Routes["/"]; | ||
export type Context = Run.MultiRouteContext<Route> & Marko.Global; | ||
export type Handler = Run.HandlerLike<Route>; | ||
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ | ||
export const route: Run.HandlerTypeFn<Route>; | ||
} | ||
} | ||
|
||
type Routes = { | ||
"/": { verb: "get" | "post"; }; | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/run/src/__tests__/fixtures/all-http-verbs/__snapshots__/dev.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Loading | ||
|
||
```html | ||
page: GET / | ||
``` | ||
|
||
# Step 0 | ||
()=>assertNoBody("HEAD") | ||
|
||
# Step 1 | ||
()=>assertBody("POST") | ||
|
||
# Step 2 | ||
()=>assertBody("PUT") | ||
|
||
# Step 3 | ||
()=>assertBody("DELETE") | ||
|
||
# Step 4 | ||
()=>assertBody("PATCH") | ||
|
||
# Step 5 | ||
()=>assertBody("OPTIONS") | ||
|
24 changes: 24 additions & 0 deletions
24
...ges/run/src/__tests__/fixtures/all-http-verbs/__snapshots__/preview.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Loading | ||
|
||
```html | ||
page: GET / | ||
``` | ||
|
||
# Step 0 | ||
()=>assertNoBody("HEAD") | ||
|
||
# Step 1 | ||
()=>assertBody("POST") | ||
|
||
# Step 2 | ||
()=>assertBody("PUT") | ||
|
||
# Step 3 | ||
()=>assertBody("DELETE") | ||
|
||
# Step 4 | ||
()=>assertBody("PATCH") | ||
|
||
# Step 5 | ||
()=>assertBody("OPTIONS") | ||
|
14 changes: 14 additions & 0 deletions
14
packages/run/src/__tests__/fixtures/all-http-verbs/src/routes/+handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const handler: MarkoRun.Handler = (context) => { | ||
return new Response( | ||
`handler: ${context.request.method} ${context.url.pathname}`, | ||
{ headers: { "content-type": "text/plain" } }, | ||
); | ||
}; | ||
|
||
export { handler as POST } | ||
export { handler as PUT } | ||
export { handler as DELETE } | ||
export { handler as PATCH } | ||
export { handler as HEAD } | ||
export { handler as OPTIONS } | ||
|
1 change: 1 addition & 0 deletions
1
packages/run/src/__tests__/fixtures/all-http-verbs/src/routes/+page.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- page: GET ${$global.url.pathname} |
26 changes: 26 additions & 0 deletions
26
packages/run/src/__tests__/fixtures/all-http-verbs/test.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import assert from "assert"; | ||
|
||
export const steps = [ | ||
() => assertNoBody('HEAD'), | ||
() => assertBody('POST'), | ||
() => assertBody('PUT'), | ||
() => assertBody('DELETE'), | ||
() => assertBody('PATCH'), | ||
() => assertBody('OPTIONS') | ||
] | ||
|
||
async function assertBody(method: string) { | ||
const url = new URL(page.url()); | ||
const response = await page.request.fetch(url.href, { method }); | ||
assert.equal(response.ok(), true, `Response for ${method} is not ok`); | ||
const body = await response.text(); | ||
assert.equal(body, `handler: ${method} ${url.pathname}`, `Response for ${method} has an unexpected body: "${body}"`); | ||
} | ||
|
||
async function assertNoBody(method: string) { | ||
const url = new URL(page.url()); | ||
const response = await page.request.fetch(url.href, { method }); | ||
assert.equal(response.ok(), true, `Response for ${method} is not ok`); | ||
const body = await response.text(); | ||
assert.equal(body, '', `Response for ${method} has a non-empty body: "${body}"`); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/run/src/__tests__/fixtures/all-http-verbs/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig-base.json", | ||
"include": ["src/**/*", ".marko-run/*"], | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/run/src/__tests__/fixtures/default-get-as-head/.marko-run/routes.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. | ||
Do NOT manually edit this file or your changes will be lost. | ||
*/ | ||
|
||
import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; | ||
import type * as Run from "@marko/run"; | ||
|
||
|
||
declare module "@marko/run" { | ||
interface AppData extends Run.DefineApp<{ | ||
routes: { | ||
"/": Routes["/"]; | ||
} | ||
}> {} | ||
} | ||
|
||
declare module "../src/routes/+page.marko" { | ||
namespace MarkoRun { | ||
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; | ||
export type Route = Run.Routes["/"]; | ||
export type Context = Run.MultiRouteContext<Route> & Marko.Global; | ||
export type Handler = Run.HandlerLike<Route>; | ||
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ | ||
export const route: Run.HandlerTypeFn<Route>; | ||
} | ||
} | ||
|
||
type Routes = { | ||
"/": { verb: "get"; }; | ||
} |
9 changes: 9 additions & 0 deletions
9
...es/run/src/__tests__/fixtures/default-get-as-head/__snapshots__/dev.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Loading | ||
|
||
```html | ||
page: GET / | ||
``` | ||
|
||
# Step 0 | ||
()=>requestHead() | ||
|
9 changes: 9 additions & 0 deletions
9
...un/src/__tests__/fixtures/default-get-as-head/__snapshots__/preview.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Loading | ||
|
||
```html | ||
page: GET / | ||
``` | ||
|
||
# Step 0 | ||
()=>requestHead() | ||
|
1 change: 1 addition & 0 deletions
1
packages/run/src/__tests__/fixtures/default-get-as-head/src/routes/+page.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- page: GET ${$global.url.pathname} |
14 changes: 14 additions & 0 deletions
14
packages/run/src/__tests__/fixtures/default-get-as-head/test.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import assert from "assert"; | ||
|
||
export const steps = [ | ||
() => requestHead(), | ||
] | ||
|
||
async function requestHead() { | ||
const url = new URL(page.url()); | ||
const response = await page.request.fetch(url.href, { method: 'HEAD' }); | ||
const headers = response.headers(); | ||
assert.equal(response.ok(), true); | ||
assert.match(headers['content-type'], /text\/html/); | ||
assert.equal(await response.body(), ''); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/run/src/__tests__/fixtures/default-get-as-head/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig-base.json", | ||
"include": ["src/**/*", ".marko-run/*"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.