Difficulty getting Netlify Dev to work for local Routify development with Functions

I’m new at web dev, so this might be poorly worded…

I’m using Functions to get around a CORS issue with an API I’ll be using for a little Routify web app. I got it working, but not locally. The problem seems to be that the netlify dev command gives me two separate servers at two different ports, one for functions at port 8888 and a web server at port 5000. Sending requests to an endpoint url using the former port works fine (confirmed with Postman). But my client at port 5000 can’t reach that endpoint, because of CORS. The deployed site works fine.

Maybe the server at port 8888 is supposed to have it all, but if so, it fails at the web part. When I visit it in the browser, it shows this mysterious text: “e[91mâ—ˆe[39m Function invocation failed: [object Object]”, and the console shows three statuscode 500 errors.

I suppose this might have something to do with a proxy, but the Netlify Dev docs explicitly says “One immediate benefit is no need for proxying since Netlify Dev does that for you”. Or it could have something to do with the project type detector. There isn’t one for Routify, and I have no idea what to write in the netlify.toml under [dev].

Does this sound familiar to anyone? Any help is deeply appreciated!

My project is almost all Routify boilerplate. I assume the scripts/netlify/netlify.toml is where I need to make changes for netlify dev to work properly.

I got it to work! Basically, instead of using scripts/netlify as base, and its SSR build script, I made a netlify.toml in the root directory with publish: dist/ and copied over the # SPA only part of [[redirects]] from the toml in the scripts/netlify folder. I also moved the functions from that folder to root, and added a functions = "api/" in my toml.

That’s about as well as I can explain it, because I don’t really understand how things work at a deep level. But maybe someone might find this useful regardless.

1 Like

Hey @gorm! Many thanks for sharing this in case others run into something similar :raised_hands: if you could share your full netlify.toml, that might make it even a bit easier to grasp at a glance. Thanks again.

Good point. Here it is:

  publish = "dist/"
  command = "npm run build"
  functions = "api/"

  # SPA only
  from = "/*"
  to = "/__app.html"
  status = 200
1 Like