Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

200 redirect rules are treated as force=true (local file shadowing not working) #851

Closed
overlordofmu opened this issue Apr 23, 2020 · 9 comments · Fixed by #843 or #949
Closed

200 redirect rules are treated as force=true (local file shadowing not working) #851

overlordofmu opened this issue Apr 23, 2020 · 9 comments · Fixed by #843 or #949
Labels
type: bug code to address defects in shipped code

Comments

@overlordofmu
Copy link

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

This is a bug report for the netlify dev handling of 200 redirect rules.

- What is the current behavior?

When netlify dev processes a 200 redirect it will always redirect even if the local file/asset exists. This is particularly problematic for the SPA rule below:

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

The 200 redirect should only occur for URLs with no static file for that URL.

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

You can clone this repo to test (which wasn't created for this purpose - sorry about the name).

https://github.com/overlordofmu/nlm-fake-ssg-site-NO-NLM

Reproduction steps follow.

mkdir -p ~/tmp
cd ~/tmp
git clone https://github.com/overlordofmu/nlm-fake-ssg-site-NO-NLM
cd nlm-fake-ssg-site-NO-NLM
./copy-build.sh #this is a fake build command and required to test
netlify dev #assuming you already have it installed and up to date

Click on the https://localhost:8888 link.

Open dev tools, click on the network tab, refresh the page. Note, the file large.jpg exists but index.html is served.

You can see this with curl also:

$ curl -sv https://localhost:8888/large.jpg
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET /large.jpg HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< x-powered-by: netlify-dev
< date: Thu, 23 Apr 2020 02:40:06 GMT
< content-type: text/html
< content-length: 463
< connection: close
<
<html>
<head></head>
  <body>
    <h1 style="text-align: center;">This is page one.</h1>
    <p>&nbsp;</p>
    <img src="large.jpg">
    <img src="large.jpg?nf_resize=fit&w=250">
    <img src="large.jpg?nf_resize=fit&w=500">
    <img src="large.jpg?nf_resize=fit&w=1000">
    <img src="large.jpg?nf_resize=fit&w=1200">
    <img src="large.jpg?nf_resize=fit&w=2000">
    <p style="text-align: center;"><a href="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/Page-2/index.html">page 2</a></p>
  </body>
</html>
* Closing connection 0

The contents of index.html are being sent in place of the actual image.

- What is the expected behavior?

The 200 redirect should only occur for assets which are not present in the publish directory.

- Local Environment Information

$ netlify version --verbose
────────────────────┐
 Environment Info   │
────────────────────┘

  System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v10.16.0/bin/npm
  Browsers:
    Chrome: 81.0.4044.122
    Firefox: 75.0
    Safari: 13.1
  npmGlobalPackages:
    netlify-cli: 2.47.0

netlify-cli/2.47.0 darwin-x64 node-v10.16.0
@overlordofmu overlordofmu added the type: bug code to address defects in shipped code label Apr 23, 2020
@j-o-sh
Copy link

j-o-sh commented Jun 11, 2020

Unfortunately this seems to still be not solved. I'm still getting the same behaviour (redirects when the real site exists) with framework='#static" and a publish folder set.

@RaeesBhatti
Copy link
Contributor

@j-o-sh Can you elaborate please! Can you please show us your netlify.toml and your directory structure!

@j-o-sh
Copy link

j-o-sh commented Jun 12, 2020

Hi @RaeesBhatti
Thx for looking into this.

So after a bit of digging around I think it has something to do specificallyt with redirects to functions.

In the redirect in the netlify.toml below you see two different to= values. One of them commented out. When I am redirecting to the commented out route (which is a normal static route) everything seems to work fine. As soon as I redirect to the .netlify/functions/... path, the redirect will always happen, even when a 'real' page exists.

[build]
command='npm run build'
publish='dist/site'
functions='dist/functions/'

[dev]
framework='#static'
publish='dist/site'

[[redirects]]
from='/wishes.mine/*'
#to='/?x=:splat'
to='/.netlify/functions/wishes_render_mine?key=:splat'
status=200

@j-o-sh
Copy link

j-o-sh commented Jun 12, 2020

I did manage to isolate the problem in a very simple repo.

Check out this repo. The problem is reproduced there.

@j-o-sh
Copy link

j-o-sh commented Jun 15, 2020

Hi there,

Would it be helpful to create a new ticket with those findings? Or would you rather like to reopen this ticket?

Do you already have an idea what could cause this?

Sorry if I'm being intrusive.

@RaeesBhatti
Copy link
Contributor

@j-o-sh Thank you for reporting this issue. I think I was able to reproduce and fix the problem. Can you please try out #949 branch and let us know if that works as expected!

@j-o-sh
Copy link

j-o-sh commented Jun 17, 2020

Hi, Sorry for the delay.

I see you already closed the issue again, which is fine I guess. ;)

...I am a bit puzzled however as to how I can try out that branch as you suggested? Can I somehow npm install from there? or is there another way? ...sorry if that seems like a stupid question.

@j-o-sh
Copy link

j-o-sh commented Jun 17, 2020

Ok, I kinda hacked it to get it to work...

But yay the fix holds 👍 👯

thx so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
3 participants