# Redirects to function endpoints not working using netlify cli "netlify dev"

**URL:** <https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212>\
**Category:** Support\
**Tags:** netlify-cli, redirects\
**Created:** [May 7, 2020, 3:03pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212 "2020-05-07T15:03:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![willkp](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/willkp/32/10401_2.png) [@willkp](https://answers.netlify.com/u/willkp)\
**Post date:** [May 7, 2020, 3:03pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/1 "2020-05-07T15:03:47Z")

</div>

I’ve got a project where I had some redirect rules set up to handle some “functions” endpoints. It worked well for a while but when I updated the CLI version recently it seems to have stopped.

I can hit a function path directly, as in` http://localhost:8888/.netlify/functions/dboxDecks/dboxDecks.js` and it will work fine.

However when I try to go to its redirect ‘from’ path `http://localhost:8888/decks` it simply serves the root, index file of the project .

I should point out that when I used to run `netlify dev` a secondary terminal window launched and displayed some port information. Now this does not happen.

Here’s my netlify.toml file:

```
[build]
  publish = "build"
  functions = "functions"

[[redirects]]
  from = "/generate"
  to = "/.netlify/functions/generateSignature/generateSignature.js"
  status = 200

[[redirects]]
  from = "/decks"
  to = "/.netlify/functions/dboxDecks/dboxDecks.js"
  status = 200

[[redirects]]
  from = "/slides"
  to = "/.netlify/functions/dboxSlides/dboxSlides.js"
  status = 200

[[redirects]]
  from = "/thumbnail"
  to = "/.netlify/functions/dboxDeckThumbnail/dboxDeckThumbnail.js"
  status = 200

```

Anyone know what’s going on?

---

<div class="post-metadata">

**Author:** ![Scott](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/scott/32/26136_2.png) [@Scott](https://answers.netlify.com/u/Scott)\
**Post date:** [May 7, 2020, 3:53pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/3 "2020-05-07T15:53:37Z")

</div>

Hey there,

Can you give this topic a read, please, and let me know if this helps?

> [@Netlify dev Error](https://answers.netlify.com/t/netlify-dev-error/13735):
>
> I want to use redirects in gatsby. I installed netlify-cli and added netlify.toml file in the root folder. In netlify-toml file [[redirects]] from = “/search/\*” to = “/search” status = 200 When I run netlify dev, I’ve got this following errors. Warnings while parsing netlify.toml file: TypeError: Cannot convert object to primitive value at ~/npm-global/lib/node\_modules/netlify-cli/src/utils/rules-proxy.js:15:46 at Array.forEach () at parseFile (~/npm-global/lib/node\_modules/netlify-cl…

---

<div class="post-metadata">

**Author:** ![willkp](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/willkp/32/10401_2.png) [@willkp](https://answers.netlify.com/u/willkp)\
**Post date:** [May 7, 2020, 4:22pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/4 "2020-05-07T16:22:52Z")

</div>

So I uninstalled netlify cli and reinstalled with `npm i -g netlify-cli@latest ` and the issue still persists.

---

<div class="post-metadata">

**Author:** ![raeesbhatti](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/raeesbhatti/32/8972_2.png) [@raeesbhatti](https://answers.netlify.com/u/raeesbhatti)\
**Post date:** [May 8, 2020, 8:37pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/6 "2020-05-08T20:37:49Z")

</div>

@willkp Can you please post the results of `netlify version --verbose`!

---

<div class="post-metadata">

**Author:** ![existo](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/existo/32/8808_2.png) [@existo](https://answers.netlify.com/u/existo)\
**Post date:** [May 10, 2020, 6:29pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/7 "2020-05-10T18:29:38Z")

</div>

I have the same problem.

When I run `$ netlify dev` or `$ netlify dev --live` the redirects rules does not works.

If I publish the project all run correctly.

My Netlify config file is like that:

```
[build]
    command = "npm run build"
    publish = "dist"
    functions = "functions"
[dev]
    framework = "#custom"
    command = "npm run dev"
    targetPort = 3030

```

My `_redirects` file is that:

```
/api	/.netlify/functions/api 200

```

This is not only a issue with functions redirects. It’s not working with any redirect rule.

Here the link to the demo project in production:

[https://nervous-allen-34edcb.netlify.app/](https://nervous-allen-34edcb.netlify.app/)

Here the link to the code:

[https://github.com/juanmiguelguerrero/auth0-test](https://github.com/juanmiguelguerrero/auth0-test)

And a capture with my `netlify version --verbose!`

 ![Captura de pantalla 2020-05-10 a las 20.18.46](https://global.discourse-cdn.com/netlify/original/2X/e/e6b1f9fdf0b9517aff40f3a620f8075f7bc22bba.png)

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [May 11, 2020, 10:53pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/8 "2020-05-11T22:53:50Z")

</div>

As far as I know, we cannot host functions with the string “api” in their name - obscure bug. Mind trying it with a differently named function just to be sure?

---

<div class="post-metadata">

**Author:** ![existo](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/existo/32/8808_2.png) [@existo](https://answers.netlify.com/u/existo)\
**Post date:** [May 12, 2020, 4:49am UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/9 "2020-05-12T04:49:29Z")

</div>

Hi fool,

Using the string “api” in the name of my functions works well on Dev and Production. I can’t find any obscure bug.

However, I have changed the name of the function and the redirection and the problem persists.

Where there is a bug is in the latest version of Netlify CLI.

I found this and It’s not only a Gatsby problem:

> <https://github.com/netlify/cli/issues/890>
>
> \*Note: I'm still working on a minimal reproduction, but you can check on the \[li…ve site\](https://master--dailytexascountry.netlify.app/store).\*
> 
> \---
> 
> \### Do you want to request a \_feature\_ or report a \_bug\_?
> 🐛 bug
> 
> \### What is the current behavior?
> First, see this \[Twitter discussion\](https://twitter.com/bradgarropy/status/1258993787990409217) with @jlengstorf.
> 
> I defined the following redirect in \`netlify.toml\`.
> 
> \`\`\`
> \[\[redirects\]\]
> from = "/api/\*"
> to = "/.netlify/functions/:splat"
> status = 200
> \`\`\`
> 
> Then in my application I have a serverless function located at \`/.netlify/functions/subscribe\`.
> I hit it via a \`POST\` request using the browser's \`fetch\` API like this.
> 
> \`\`\`
> const options = {
> method: "POST",
> body: JSON.stringify(data),
> headers: {"Content-Type": "application/json"},
> }
> 
> const response = await fetch("/api/subscribe", options)
> \`\`\`
> 
> It returns an HTML document rather than the expected JSON output.
> 
> \`\`\`
> \<!DOCTYPE html\>\<html\>\<head\>\<meta charSet="utf-8"/\>\<meta http-equiv="x-ua-compatible" content="ie=edge"/\>\<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/\>\<meta name="note" content="environment=development"/\>\<title data-react-helmet="true"\>\</title\>\<link href="https://fonts.googleapis.com/css?family=Inter|Roboto|Patua+One" rel="stylesheet"/\>\<style type="text/css"\>
> .anchor.before {
> position: absolute;
> top: 0;
> left: 0;
> transform: translateX(-100%);
> padding-right: 4px;
> }
> .anchor.after {
> display: inline-block;
> padding-left: 4px;
> }
> h1 .anchor svg,
> h2 .anchor svg,
> h3 .anchor svg,
> h4 .anchor svg,
> h5 .anchor svg,
> h6 .anchor svg {
> visibility: hidden;
> }
> h1:hover .anchor svg,
> h2:hover .anchor svg,
> h3:hover .anchor svg,
> h4:hover .anchor svg,
> h5:hover .anchor svg,
> h6:hover .anchor svg,
> h1 .anchor:focus svg,
> h2 .anchor:focus svg,
> h3 .anchor:focus svg,
> h4 .anchor:focus svg,
> h5 .anchor:focus svg,
> h6 .anchor:focus svg {
> visibility: visible;
> }
> \</style\>\<script\>
> document.addEventListener("DOMContentLoaded", function(event) {
> var hash = window.decodeURI(location.hash.replace('#', ''))
> if (hash !== '') {
> var element = document.getElementById(hash)
> if (element) {
> var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
> var clientTop = document.documentElement.clientTop || document.body.clientTop || 0
> var offset = element.getBoundingClientRect().top + scrollTop - clientTop
> // Wait for the browser to finish rendering before scrolling.
> setTimeout((function() {
> window.scrollTo(0, offset - 0)
> }), 0)
> }
> }
> })
> \</script\>\<link rel="preconnect" href="https://instagram.com"/\>\<script src="/socket.io/socket.io.js"\>\</script\>\</head\>\<body\>\<div id="\_\_\_gatsby"\>\</div\>\<script\>
> window.gatsbyLoadInstagram = function() {
> var js = document.createElement('script');
> var firstScript = document.getElementsByTagName('script')\[0\];
> js.id = 'gatsby-plugin-instagram';
> js.src = 'https://instagram.com/embed.js';
> 
> firstScript.parentNode.insertBefore(js, firstScript);
> 
> return true;
> }
> \</script\>\<script src="/commons.js"\>\</script\>
> \</body\>\</html\>
> \`\`\`
> 
> So it seems like the \`netlify dev\` command does not respect function redirects.
> 
> \### If the current behavior is a bug, please provide the steps to reproduce.
> First get the project up and running.
> 
> \`\`\`
> git clone https://github.com/bradgarropy/dailytexascountry.com.git
> cd dailytexascountry.com
> npm install
> netlify dev
> \`\`\`
> 
> Then go to the \`/store\` page and enter your email, which will kick off the API call to \`/api/subscribe\`.
> Check the Network tab to see the unexpected HTML response.
> 
> \### What is the expected behavior?
> 
> The \`/api/subscribe\` endpoint should return a JSON object.
> 
> \### Local Environment Information
> 
> \`\`\`
> ────────────────────┐
> Environment Info │
> ────────────────────┘
> 
> System:
> OS: Windows 10 10.0.18363
> CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
> Binaries:
> Node: 12.13.1 - D:\\nodejs\\node.EXE
> Yarn: 1.22.4 - ~\\AppData\\Roaming\\npm\\yarn.CMD
> npm: 6.14.5 - D:\\nodejs\\npm.CMD
> Browsers:
> Edge: 44.18362.449.0
> 
> netlify-cli/2.50.0 win32-x64 node-v12.13.1
> \`\`\`

Thanks

---

<div class="post-metadata">

**Author:** ![Scott](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/scott/32/26136_2.png) [@Scott](https://answers.netlify.com/u/Scott)\
**Post date:** [May 13, 2020, 1:57pm UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/10 "2020-05-13T13:57:54Z")

</div>

Hey there,

Thanks for closing the loop and linking the bug.

As per [function redirects are not working with netlify dev · Issue #890 · netlify/cli · GitHub](https://github.com/netlify/cli/issues/890), `netlify-cli@2.51.0` has just been released which contains a fix for this issue.

---

<div class="post-metadata">

**Author:** ![existo](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/existo/32/8808_2.png) [@existo](https://answers.netlify.com/u/existo)\
**Post date:** [May 16, 2020, 10:17am UTC](https://answers.netlify.com/t/redirects-to-function-endpoints-not-working-using-netlify-cli-netlify-dev/14212/11 "2020-05-16T10:17:32Z")

</div>

Everything is fine width the update.

Thanks.
