Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Route group with API does not work #1176

Closed
2 tasks done
ryoid opened this issue Dec 25, 2023 · 4 comments
Closed
2 tasks done

[Bug?]: Route group with API does not work #1176

ryoid opened this issue Dec 25, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@ryoid
Copy link
Contributor

ryoid commented Dec 25, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Creating route group with API Route returns 404.

Expected behavior 🤔

API route shout work

Steps to reproduce 🕹

Steps:

  1. pnpm create solid basic
  2. Create route group with API route /routes/(group)/endpoint.tsx
// folder structure
|-- routes/
    |-- (group)
        |-- page.tsx         // http://example.com/page - works
        |-- endpoint.tsx     // http://example.com/endpoint - not found

// endpoint.tsx
export function GET() {
  return new Response("Hello World")
}

// page.tsx
export default function Page() {
  return (
    <main>
      <h1>Page</h1>
    </main>
  )
}
  1. Go to http://localhost:3000/endpoint, 404
  2. Go to http://localhost:3000/page, page in same route group displays

Context 🔦

Trying to group API routes that generate sitemap.xml and robots.txt

|-- routes/
    |-- (sitemeta)
        |-- sitemap.xml.ts
        |-- robots.txt.ts

Reproduction
https://github.com/ryoid/solidstart-bug-grouped-api-route

Your environment 🌎

Node 20.10.0

"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.10.5",
"@solidjs/start": "^0.4.2",
"solid-js": "^1.8.7",
"vinxi": "0.0.54"
https://github.com/ryoid/solidstart-bug-grouped-api-route/blob/main/package.json
@ryoid ryoid added the bug Something isn't working label Dec 25, 2023
@ryoid ryoid changed the title [Bug?]: [Bug?]: Route group with API does not work Dec 25, 2023
@jzohdi
Copy link
Contributor

jzohdi commented Dec 26, 2023

Hi @ryoid, I started to inspect this issue and have opened a pull request here to show what I believe the issue to be.

@ryansolid could I be assigned this issue? Note: I am still in the process of testing/adding tests to the PR

@apademide
Copy link

I stumbled upon the same issue yesterday and described it here on Discord.

In the current implementation, it's expected that those grouping segments in API routes don't work, because they're just not handled at all. UI routes will replace any /(...) matching segment, but API routes won't do anything on them. This means in your repro, you wouldn't be able to access localhost/endpoint, but localhost/(group)/endpoint would work.

I only hope this is an overlook and not a design choice, since grouping adds as much convenience on API routes as it does with UI ones.

@jzohdi
Copy link
Contributor

jzohdi commented Dec 30, 2023

Thanks @apademide for your detailed write up on discord!

A replacement strategy similar to how UI routes implement it for groups would with consideration to maintaining the "scoring" order of routes to match. I can include this in my PR and also be sure to add documentation to make the expected behavior more clear.

@ryansolid
Copy link
Member

Thanks so much for your work @jzohdi this issue. PR is merged and will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants