What's the port that 'vercel dev' command serves the APIs at? #4634
-
My understanding of how 'dev' command works if there's a corresponding 'dev' script in package.json is that: a. it runs a proxy server at the port set with '-l' e.g. 5000 Let's assume my 'routes' field in now.json is empty. Then what happens if I call localhost:5000, all those calls will be proxied to localhost:57456 Let's say I have a webpack dev server running at localhost:57456 which serves the static files and handles routing of my SPA/PWA. Now, my question is that what is the port that the APIs are served at? If I ping 'localhost:5000/api/my-api' it'll simply be proxied to 'localhost:57456/api/my-api'. I can setup a proxiy on webpack dev server to proxy that to the real API port, but what's that port? Alternatively, I assume somehow I might be able to set 'routes' in now.json in a way that calls to localhost:5000 are directly sent to my API, but I've tried various configurations and it doesn't seem to work. If I don't have a 'dev' script and 'vercel dev' serves the static files created by my build script itself, everything works as expected. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
When you run Both the frontend static files and the backend serverless functions are served on the same port, just like in production deployments. So the path for functions is always |
Beta Was this translation helpful? Give feedback.
-
K, I just had a work around and it works:
So what's happening now is that if I run 'now dev' it starts my devServer at 8080, it starts "@vercel/node" dev server at $PORT, and then it also starts the proxy at 3000. Now I can access my devServer at 8080. I think Vercel dev guides which suggest passing $PORT as the port of your internal devServer/framework are misleading for a completely custom setup; it works for say next.js which is aware of how 'vercel dev' works and is setup to work with it, but not when you're running your own devServer. p.s. The previous work around that I had was to rename 'dev' to another script that's not automatically picked up by Vercel e.g. 'start:dev' and then do 'vercel dev' + 'npm run start:dev' together. This work around just saves me from having to run two commands, but still :D |
Beta Was this translation helpful? Give feedback.
-
Maybe I'm misunderstanding the problem, but your dev command should always look like Can you create a hello world example that fails to follow this behavior? |
Beta Was this translation helpful? Give feedback.
-
I have a Remix project with Vite. I have configured my project to run |
Beta Was this translation helpful? Give feedback.
Maybe I'm misunderstanding the problem, but your dev command should always look like
something develop --port $PORT
for examplegatsby develop -p $PORT
ornext -p $PORT
.Can you create a hello world example that fails to follow this behavior?