T
TanStack7d ago
correct-apricot

POST requests hang forever

I'm trying to deploy my app using caddy as a reverse proxy. My Tanstack Start app (behind fastify) works fine using docker but as soon as I add caddy:
services:
proxy:
image: caddy:2-alpine
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile

app:
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- PORT=3000
services:
proxy:
image: caddy:2-alpine
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile

app:
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- PORT=3000
where Caddyfile is:
:80 {
encode gzip zstd

reverse_proxy app:3000 {
header_up Host {host}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
:80 {
encode gzip zstd

reverse_proxy app:3000 {
header_up Host {host}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
then GET requests work fine (even files) but POST requests hang forever. Does anyone have any idea what could cause this?
15 Replies
correct-apricot
correct-apricotOP7d ago
The POST request reaches fastify for sure (since I see a incoming request log in Fastify). It's a POST request made by Tanstack Query (using the native integration with Tanstack Start) to a server function. If I add a console.info to the start of the function it never gets executed. Without the proxy the app works just fine (including post requests and even file uploads)
correct-apricot
correct-apricotOP7d ago
This is the Fastify server file. Probably not the source of the issue but might as well...
harsh-harlequin
harsh-harlequin7d ago
can you provide a full reproducer project that is easily runnable?
correct-apricot
correct-apricotOP7d ago
GitHub
chore: POST request hanging by shoooe · Pull Request #2 · shoooe/...
Steps to reproduce Run docker compose up --build --force-recreate Go to localhost:3000 (home page) Click "Run POST request" Notice the POST request hangs forever
harsh-harlequin
harsh-harlequin7d ago
can you please create a github issue for this in the router repo? otherwise its hard to track all the open topics
correct-apricot
correct-apricotOP7d ago
Yup. I wasn't sure it was a bug
harsh-harlequin
harsh-harlequin7d ago
i dont know either but if in doubt, just create an issue with a reproducer we will eventually figure it out
correct-apricot
correct-apricotOP7d ago
Here it is: https://github.com/TanStack/router/issues/5275 Closing this topic then
GitHub
POST requests hang forever when behind a proxy · Issue #5275 · Ta...
Which project does this relate to? Router Describe the bug The Tanstack Start app works just fine without a reverse proxy. As soon as I add a simple reverse proxy (Caddy) then GET requests keep wor...
correct-apricot
correct-apricotOP7d ago
Seems like Caddy is not the issue. Seems like toNodeHandler is the culprit. It's reproducible even in a regular pnpm build && pnpm start now
harsh-harlequin
harsh-harlequin7d ago
can you reproduce outside of start? with just toNodeHandler and a dummy handler?
correct-apricot
correct-apricotOP7d ago
What's the dummiest handler?
fetch(request: Request) {
return new Response();
}
fetch(request: Request) {
return new Response();
}
?
harsh-harlequin
harsh-harlequin7d ago
thats very dummy! might want to try a async version as well if that does not fail
correct-apricot
correct-apricotOP7d ago
It's not reproducible neither with that nor with the async version of that Seems like toNodeHandler + import handler from "@tanstack/react-start/server-entry" is the problem It's reproducible even without input data (although Tanstack Start seems to send something anyway)
harsh-harlequin
harsh-harlequin7d ago
It's reproducible
with or without start?
correct-apricot
correct-apricotOP7d ago
with start it's only reproducible when you mix toNodeHandler and @tanstack/react-start/server-entry oh yeah and then there's the whole cross site request thing as well (if you are thinking about using GET for mutations)

Did you find this page helpful?