Reject Next-Action probes before the SSR handler
POST / with a React server-actions header is not a request this app
makes — TanStack server functions POST to /_serverFn/<id>. Left alone
the transform stream sat open until the 120s lifetime timer force-cleaned
it, surfacing as a fatal uncaught exception in Sentry (event e267e264,
release 84dffa8). Now answered 404 in 9ms; normal pages unaffected.
This commit is contained in:
1 parent
84dffa8451
commit
1419c1d9ee
1 file changed
+10
+10
@@ -137,6 +137,16 @@ async function toWebRequest(req, url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendFromHandler(req, res) {
|
async function sendFromHandler(req, res) {
|
||||||
|
// TanStack server functions POST to /_serverFn/<id>; a POST carrying the
|
||||||
|
// React server-actions header anywhere else is a probe (bots love
|
||||||
|
// `Next-Action: x`). Left alone it ties up an SSR stream until the 120s
|
||||||
|
// lifetime timer force-cleans it and Sentry reports a fatal uncaught
|
||||||
|
// exception — so reject it before the handler ever sees it.
|
||||||
|
if (req.headers["next-action"] !== undefined) {
|
||||||
|
res.writeHead(404, { "content-type": "text/plain" });
|
||||||
|
res.end("not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const url = `http://${req.headers.host ?? `${HOST}:${PORT}`}${req.url}`;
|
const url = `http://${req.headers.host ?? `${HOST}:${PORT}`}${req.url}`;
|
||||||
const request = await toWebRequest(req, url);
|
const request = await toWebRequest(req, url);
|
||||||
const response = await handler.fetch(request);
|
const response = await handler.fetch(request);
|
||||||
|
|||||||
Reference in new issue
Block a user