DiiiaZoTe / next-route-visualizer

https://next-route-visualizer.vercel.app
Other
490 stars 16 forks source link

Get the running pathname to get the right application port #3

Closed ThibautCuchet closed 1 year ago

ThibautCuchet commented 1 year ago

Hi @DiiiaZoTe, nice job for this good package to visualize app structure.

There is a small bug about the "Link" field, it always shows port 3000. If the application launches on another port and the user has not overridden the default value of "baseURL" in the "" component, it will also have port 3000. In this example, we can see that my application is running on port 3001. Screenshot 2023-03-13 at 11 38 43

I tried to look around a bit, unfortunately, Next 13 does not allow access to the "pathname" on the server side. So maybe "" component which is client side could retrieve the pathname if "baseURL" is not set.

DiiiaZoTe commented 1 year ago

So yes, the default is 3000. If you use a different port, please override the baseURL.

In the example above, if you did override the baseURL, it would have shown http://localhost:3001 because you are in (booking) which is a route group. This not in the route tree.

Let me double check though.

ThibautCuchet commented 1 year ago

Yes, you right the url is good but I mean the package could use the running port instead of "3000" by default.

DiiiaZoTe commented 1 year ago

The problem is that Nextjs doesn't allow you to get the current running port that I know of. Unless you set it explicitly in you package.json with next dev -p XXXX. Otherwise, process.env.PORT gives you undefined, that's why I left it for anyone to set their baseURL. That's unfortunately some limitations from Nextjs that I can't work around.

Try to log your process.env at the top of your app/page.tsx and you'll see they don't set it anywhere either. They must be doing it somewhere internally.