cli icon indicating copy to clipboard operation
cli copied to clipboard

Functions 404 with Netlify Dev and a linked project

Open jbool24 opened this issue 5 years ago • 1 comments

- Do you want to request a feature or report a bug? BUG

- What is the current behavior? All functions return 404 not found running netlify dev when netlify link is initialized. Meaning the directory .netlify exists in the project root allong with state.json in that directory filled with its proper site id.

# PROJECT_ROOT/.netlify/state.json
{
    "siteId": SOME_SITE STRING
}

- If the current behavior is a bug, please provide the steps to reproduce.

  1. add new project in netlify and also create a new directory locally with a functions directory and at least one function. (do NOT link or init local dir yet)
  2. add netlify.toml configuration to project root with splat proxy redirect to functions (see netlify.toml setup below)
  3. first run netlify dev and test route using curl hitting proxy default: localhost:8888/api/yourFunc this should return a response correctly
  4. now run netlify link to link up the project created in netlify platform
  5. restart netlify dev and re-curl proxy endpoint default: localhost:8888/api/yourFunc. Now you get 404 response

- What is the expected behavior?

  1. netlify dev should use all local configuration regardless of linking the project or not.
  2. Also env injection should be available via a flag not by default. The functions should return as usual without using any network. NOTE: this fails even with the --offline flag appended
  3. When linked the base directory should be implied the current working directory, no? Sensible default

- Local Environment Information Using defaults aside from a redirect proxy splat rule in netlify.toml

[build]
    command = "#"
    publish = "public/"
    functions = "functions"

[[redirects]]
    from = "/api/*"
    to = "/.netlify/functions/:splat"
    status = 200
    force = true

Running netlify dev without linking

◈ Netlify Dev ◈                                                                                                                                 
◈ No app server detected and no "command" specified                                                                                             
◈ Running static server from "netlify-serverless/public"   <-- CORRECT DEFAULTS                                                              
                                                                                                                                                
◈ Server listening to 3999                                                                                                                      
                                                                                                                                                
◈ Functions server is listening on 34121                                                                                                        
                                                                                                                                                
   ┌─────────────────────────────────────────────────┐                                                                                          
   │                                                 │                                                                                          
   │   ◈ Server now ready on http://localhost:8888   │                                                                                          
   │                                                 │                                                                                          
   └─────────────────────────────────────────────────┘                                                                                          
                                                                                                                                                
◈ Rewrote URL to /.netlify/functions/someFunc                                                                                                      
Request from ::ffff:127.0.0.1: GET /.netlify/functions/someFunc                                                                                                                                           
Response with status 200 in 10 ms.       

Running netlify dev with project linked (ie .netlify/state.json in project root)

◈ Netlify Dev ◈
◈ No app server detected and no "command" specified
◈ Running static server from "netlify-serverless/public/public" <-- NOTICE because 'base' is not set in netlify.toml

◈ Server listening to 3999

◈ Functions server is listening on 40657

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Rewrote URL to /.netlify/functions/someFunc
Request from ::ffff:127.0.0.1: GET /.netlify/functions/someFunc
Response with status 404 in 4 ms.

netlify-cli/2.54.0 linux-x64 node-v12.16.2

jbool24 avatar Jun 25 '20 14:06 jbool24

I noticed this issue today when walking through https://docs.netlify.com/get-started/. The redirect worked until I ran ntl link.

netlify-cli/9.13.0 linux-x64 node-v16.14.0

ddrake avatar Mar 12 '22 00:03 ddrake

Hey @jbool24 & @ddrake, I was trying to debug this but couldn't reproduce the issue. I'm using netlify-cli/11.8.3. Can you update the cli package and let me know if you're still experiencing the issue.

tinfoil-knight avatar Sep 28 '22 17:09 tinfoil-knight

Closing as stale. Please re-open if needed

sarahetter avatar Sep 14 '23 14:09 sarahetter