[edge_functions] Adding a hello world returns 404 locally

Hi Support

I want to start using your edge_functions specifically the geolocation, I am following this blog post step by step.

I have a gatsby project running locally which runs no problem on my localhost:8888

I have added into my project the netlify/edge-functions/hello.js which contains

export default async (Request) => {
  return new Response("Hello, World!", {
    headers: { "content-type": "text/html" },
  });
};

I have then added to my netlify.toml file the following:

[[edge_functions]]
function = "hello"
path = "/hello"

As its a gatsby site I have tried added the netlify/edge-functions directory at the root with the standard netlify functions folder and i have added it to the src directory.

When I request http://localhost:8888/hello i am returned with a 404 error.

Any idea what I have done wrong here?

Many thanks in advance for your help.
Simon

Hi Simon!

Some things for you to check.

Are you running the project using the Netlify CLI (rather than the Gatsby dev command)?

If not, head over to netlify-cli - npm and follow the installation instructions.

Run netlify dev in your terminal (at the root of the project) which will run the project using the CLI. This will load and run the Edge Functions for you. You should see something like this in your terminal if the Edge Function has loaded correctly:

β—ˆ Static server listening to 3999
 
β—ˆ Server now ready on http://localhost:8888 

β—ˆ Loaded edge function hello

If you’re already using the CLI:

Which version of the Netlify CLI are you running? The latest version is 10.1.0.

To check which version you are currently running, enter the following into your terminal:

netlify --version

To update the CLI package, run the following in your terminal:

npm update netlify-cli

Let me know if that helps!

1 Like

Hi @whitep4nth3r

Thank you for your reply. The CLI update fixed it, I was using version 9, and it turns out the edge_functions need to be at the root and not inside the src!

Thanks for your help on this.

2 Likes

Thanks so much for coming back and letting us know, @tinterweb! Happy building :rocket: