Nuxt 3 and redirects

Hi.

I’m a new Netlify and also Nuxt 3 user.

I would like to have /graphql endpoint so I have created redirects in:

a) _redirects file

/graphql /.netlify/functions/graphql 200!

This works on a local server (ntl dev), after changing deploy command to yarn build && cp _redirects dist/_redirects /graphql endpoint also works on Netlify, but other endpoints like home / has error 404 not found.

https://61ae9030d52edd0007c16ac3--2anycloud.netlify.app/graphql (redirect works)
https://61ae9030d52edd0007c16ac3--2anycloud.netlify.app/ (404 not found)

I have noticed that file _nuxt/_redirects already exists in dist folder with redirect:
/* /.netlify/functions/server 200

When modifying the deploy command with adding cp _redirects dist/_redirects this file gets overwritten with:
/graphql /.netlify/functions/graphql 200!

I guess this is the reason that no other endpoint is working…

Also tried to put bot rules in the _redirects file:

/* /.netlify/functions/server 200
/graphql /.netlify/functions/graphql 200!

Which is also not working in the way that the bot rules would work properly.

b) netlify.toml file

[build]

command = "yarn build"
publish = "dist"
functions = "functions"

[[redirects]]
  from = '/graphql'
  to = '/.netlify/functions/graphql'
  status = 200


[dev]

[[redirects]]
  from = '/graphql'
  to = '/.netlify/functions/graphql'
  status = 200

This also works on a local server (ntl dev), but not on Netlify.

https://61afe40dbc81c70008b427e1--2anycloud.netlify.app/graphql
https://61afe40dbc81c70008b427e1--2anycloud.netlify.app/

/graphql endpoint is not working… It looks like that / is loaded instead. The same happens with method a) without modified deploy command.

In netlify.toml file I want to set the same redirect for [build] (Netlify) and for [dev] (ntl dev) environment.

Any advice on how to make redirect work on Netlify would be much appreciated.

Kind regards, Jure.

This should work if you reverse the order of these rules.