Skip to content

Commit 551dcce

Browse files
committed
fix: resolve TrustedHostMiddleware rejecting all production requests
The api-worker was deleting the Host header, causing Cloud Run's hostname to be used instead. TrustedHostMiddleware only allowed *.trycheatcode.com, rejecting 100% of proxied requests with 400. Forward original host and allow *.run.app for direct access (Inngest callbacks, monitoring).
1 parent a1642bd commit 551dcce

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

api-worker/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export default {
4848
// Build target URL
4949
const targetUrl = `${CLOUD_RUN_URL}${url.pathname}${url.search}`;
5050

51-
// Clone headers
51+
// Clone headers, forwarding original host so TrustedHostMiddleware accepts it
5252
const headers = new Headers(request.headers);
53-
headers.delete('host');
53+
headers.set('host', url.host);
5454

5555
// Proxy request
5656
const proxyRequest = new Request(targetUrl, {

backend/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,13 @@ async def add_security_headers(request: Request, call_next):
186186

187187
app.add_middleware(
188188
TrustedHostMiddleware,
189-
allowed_hosts=["trycheatcode.com", "www.trycheatcode.com", "*.trycheatcode.com", "localhost"],
189+
allowed_hosts=[
190+
"trycheatcode.com",
191+
"www.trycheatcode.com",
192+
"*.trycheatcode.com",
193+
"*.run.app",
194+
"localhost",
195+
],
190196
)
191197

192198
app.add_middleware(

0 commit comments

Comments
 (0)