Skip to content

Commit

Permalink
Merge branch 'main' into add-deno-create-command
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid authored Oct 31, 2024
2 parents 9133c4e + 545a8ce commit ef1db4d
Show file tree
Hide file tree
Showing 6 changed files with 3,528 additions and 3,796 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-clocks-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

fix(start): enable HEAD requests to API HEAD/GET routes
16 changes: 8 additions & 8 deletions examples/with-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.14.10",
"@solidjs/start": "^1.0.9",
"@solidjs/testing-library": "^0.8.7",
"@testing-library/jest-dom": "^6.4.2",
"@solidjs/testing-library": "^0.8.10",
"@testing-library/jest-dom": "^6.6.2",
"@testing-library/user-event": "^14.5.2",
"@vitest/ui": "^1.5.0",
"jsdom": "^24.0.0",
"solid-js": "^1.9.2",
"typescript": "^5.4.5",
"@vitest/ui": "^2.1.4",
"jsdom": "^25.0.1",
"solid-js": "^1.9.3",
"typescript": "^5.6.3",
"vinxi": "^0.4.3",
"vite": "^5.2.8",
"vite": "^5.4.10",
"vite-plugin-solid": "^2.10.2",
"vitest": "^1.5.0"
"vitest": "^2.1.4"
}
}
9 changes: 8 additions & 1 deletion packages/start/config/fs-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
}
}

const HTTP_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"];
const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
function createHTTPHandlers(src, exports) {
const handlers = {};
for (const exp of exports) {
Expand All @@ -67,8 +67,15 @@ function createHTTPHandlers(src, exports) {
src: src,
pick: [exp.n]
};
if (exp.n === "GET" && !exports.find(exp => exp.n === "HEAD")) {
handlers.$HEAD = {
src: src,
pick: [exp.n]
};
}
}
}

return handlers;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/start/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Route {
children?: Route[];
page?: boolean;
$component?: any;
$HEAD?: any;
$GET?: any;
$POST?: any;
$PUT?: any;
Expand Down Expand Up @@ -57,7 +58,7 @@ function defineRoutes(fileRoutes: Route[]) {
export function matchAPIRoute(path: string, method: string) {
const match = router.lookup(path);
if (match && match.route) {
const handler = match.route[`$${method}`];
const handler = method === "HEAD" ? match.route["$HEAD"] || match.route["$GET"] : match.route[`$${method}`];
if (handler === undefined) return;
return {
handler,
Expand All @@ -67,7 +68,7 @@ export function matchAPIRoute(path: string, method: string) {
}

function containsHTTP(route: Route) {
return route["$GET"] || route["$POST"] || route["$PUT"] || route["$PATCH"] || route["$DELETE"];
return route["$HEAD"] || route["$GET"] || route["$POST"] || route["$PUT"] || route["$PATCH"] || route["$DELETE"];
}

const router = createRouter({
Expand Down
2 changes: 1 addition & 1 deletion packages/start/src/server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createBaseHandler(
const match = matchAPIRoute(new URL(event.request.url).pathname, event.request.method);
if (match) {
const mod = await match.handler.import();
const fn = mod[event.request.method];
const fn = event.request.method === "HEAD" ? mod["HEAD"] || mod["GET"] : mod[event.request.method];
(event as APIEvent).params = match.params || {};
// @ts-ignore
sharedConfig.context = { event };
Expand Down
Loading

0 comments on commit ef1db4d

Please sign in to comment.