Next.js Discord

Discord Forum

500 Internal Server Error

Unanswered
White-horned horntail posted this in #help-forum
Open in Discord
White-horned horntailOP
Hi guys, I'm trying to make an application with Next.js and FastApi for the backend. I just used this template https://vercel.com/templates/next.js/nextjs-fastapi-starter and ran it with npm run dev, but when I try to access /api/py/helloFastApi it gives me this error:
[0] Failed to proxy http://127.0.0.1:8000/api/py/helloFastApi Error: connect ECONNREFUSED 127.0.0.1:8000
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
[0]     at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
[0]   errno: -4078,
[0]   code: 'ECONNREFUSED',
[0]   syscall: 'connect',
[0]   address: '127.0.0.1',
[0]   port: 8000
[0] }
[0] Error: connect ECONNREFUSED 127.0.0.1:8000
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
[0]     at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
[0]   errno: -4078,
[0]   code: 'ECONNREFUSED',
[0]   syscall: 'connect',
[0]   address: '127.0.0.1',
[0]   port: 8000
[0] }
[0]  ✓ Compiled /favicon.ico in 442ms (362 modules)
[0]  GET /favicon.ico 200 in 1365ms

On the page it says "Internal Server Error". Can anyone tell me what this is about?

2 Replies

Try npm run fastapi-dev before you do npm run dev

You’re probably getting that error because your Next.js app is trying to access the API service and it’s not up yet. Try running the API first and then the Next app. Services are in different ports and are basically 2 different apps, so the one you’re trying to access api/py/helloFastApi is currently down.
@White-horned horntail solved?