solidjs / solid-docs-next

SolidJS Docs.
https://docs.solidjs.com/
212 stars 244 forks source link

api route example in docs doesn't seem to work #814

Open yangkennyk opened 2 months ago

yangkennyk commented 2 months ago

Describe the bug

I've been frustratingly trying to understand why I can't seem to get this example from the docs to work.

https://docs.solidjs.com/solid-start/building-your-application/api-routes

routes/api/product/[category]/brand-[brand].ts

import type { APIEvent } from "@solidjs/start/server";
import store from "./store";

export async function GET({ params }: APIEvent) {
  console.log(`Category: ${params.category}, Brand: ${params.brand}`);
  const products = await store.getProducts(params.category, params.brand);
  return products;
}

Your Example Website or App

https://stackblitz.com/edit/github-grada5-j81cuh?file=src%2Froutes%2Fapi%2Fproduct%2F%5Bcategory%5D%2Fbrand-%5Bbrand%5D.ts

Steps to Reproduce the Bug or Issue

From my understanding loading the following api route should work but I just get 404.

/api/product/tools/brand-dewalt

Expected behavior

I expected the api route to return

{
   "category":  "tools",
   "brand": "dewalt"
}

but I just get 404 on the route.

do I have a misunderstanding of how that route should work?

Screenshots or Videos

No response

Platform

Additional context

No response

ryansolid commented 2 months ago

I don't believe we support partial params that way. You'd need to have a routes/api/product/[category]/[brand].ts route and then use matchFilters to get the specific brand-____ format.

yangkennyk commented 2 months ago

I don't believe we support partial params that way. You'd need to have a routes/api/product/[category]/[brand].ts route and then use matchFilters to get the specific brand-____ format.

So is the example in the docs incorrect?

https://docs.solidjs.com/solid-start/building-your-application/api-routes

image

ryansolid commented 1 month ago

Yes I'm pretty sure it is. Sorry I missed the URL there. I will move this to the docs repo. Thanks

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

atilafassina commented 6 days ago

Thanks for pointingit out! I added the planned label so we can address this as early as possible.