Hi, we’re having problems with an edge function, it was working properly for weeks, and suddenly every page behind it starts timing out with a 504. Removing it made everything work properly again.
The function is nothing special, just a simple string replace in the content through a regex so I don’t think it is to blame, but here it is anyway:
import { Context } from 'https://edge.netlify.com';
export default async (request: Request, context: Context) => {
// Get the page content
const response = await context.next();
const page = await response.text();
// Replace the placeholder with country name
const regex = /\{\{NETLIFY_EDGE_FUNC_COUNTRY\}\}/;
const countryName = context.geo.country?.name;
const updatedPage = page.replace(regex, countryName ? 'in ' + countryName : 'everywhere');
return new Response(updatedPage, response);
};
The culprit seems to be Netlify itself, as the bug would go away and come back on its own. I have a test page where I still use the edge function and can share it with whoever wants to investigate this, but at the moment the bug seems to not be happening.