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

index api route logs not shown in Zeit, works differently in dev vs prod #11542

Closed
swyxio opened this issue Apr 1, 2020 · 6 comments · Fixed by #11643
Closed

index api route logs not shown in Zeit, works differently in dev vs prod #11542

swyxio opened this issue Apr 1, 2020 · 6 comments · Fixed by #11643

Comments

@swyxio
Copy link
Contributor

swyxio commented Apr 1, 2020

Bug report

index api route not rendered in Zeit, works differently in dev vs prod

Describe the bug

In this code i have a dynamic api route and a custom one:

/api
  /devto
    /index.ts
    /[postId].ts

In dev, this works fine:

image

but in prod, this happens:

image

It's because the api is somehow behaving differently in dev vs in prod. I should dig in further, but first I need the api route/serverless function to log its state to me

However in Zeit it doesn't show accordingly:

image

To Reproduce

https://github.com/sw-yx/dev-to-cms/tree/fea1a57ac09c8c0bd818709bd891db52e85f53fa

Expected behavior

api routes should work the same in dev as in prod and logs should.. log.

System information

  • OS: macos
  • Browser: chrome
  • Version of Next.js: 9.3.2 with Preact

Additional context

here i recorded a video bug report

https://youtu.be/bDmIGNFwu1k

@swyxio
Copy link
Contributor Author

swyxio commented Apr 1, 2020

here i recorded a video bug report

https://youtu.be/bDmIGNFwu1k

@timneutkens
Copy link
Member

Hey! I had a look into this. It seems that you are trying to fetch /api/devto/index instead of /api/devto and that the behavior with next start in Next.js is kind of unexpected. index routes are meant to serve the folder name only and not the /index variant.

We'll have a look at fixing the inconsistency.

@Janpot
Copy link
Contributor

Janpot commented Apr 1, 2020

index routes are meant to serve the folder name only and not the /index variant.

That's interesting, that will also impact the description in #10488 (comment). It would change the behavior of the second table in that comment into something a bit more consistent 👍

@swyxio
Copy link
Contributor Author

swyxio commented Apr 2, 2020

gotcha. of course i did not start out trying to fetch /api/devto/index - it was a hack after fetching /api/devto worked differently than I expected. but i was rushing thru and just randomly trying things until it worked - i will try it again "properly" and document what i find.

update.. looks like it "just works". not sure why i felt like it didnt work the first time i tried it


for what its worth, i think the docs could be clearer on how dynamic api routes can coexist with "blank routes" - this is a very common RESTful pattern:

  • GET api/posts/ - gets a list of posts, probably paginated
  • GET api/posts/12345 - gets post id 12345

how are we supposed to model this very common api route structure with dynamic api routes? the docs basically leave it up to the reader to guess.

  • option 1:
    • /api/posts.js
    • /api/posts/[postId].js
  • option 2:
    • /api/posts/index.js
    • /api/posts/[postId].js
  • option 3:
    • only /api/posts/[postId].js and handle undefined postId in the code

i'm sure one of these will work but its not clear which. i actually livestreamed my confusion playing with these options and looking at the docs, which would be good ux research, but unfortunately google lost the entire stream :(

@timneutkens
Copy link
Member

timneutkens commented Apr 2, 2020

Option 1 and 2 both work. Dynamic routes do not have an undefined state. They do not match /api/posts in your example.

Would be happy to take in PRs to clear that up 👍

swyxio added a commit to swyxio/next.js that referenced this issue Apr 2, 2020
document how root routes coexist with dynamic api routes - related to vercel#11542
timneutkens added a commit that referenced this issue Apr 2, 2020
* document how root routes coexist with dynamic api routes

document how root routes coexist with dynamic api routes - related to #11542

* Update dynamic-api-routes.md

* Update dynamic-api-routes.md

* Run prettier

Co-authored-by: Tim Neutkens <[email protected]>
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants