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

Bug: re-write rules are not applied for non static servers #1242

Closed
erezrokah opened this issue Sep 15, 2020 · 6 comments · Fixed by #5005
Closed

Bug: re-write rules are not applied for non static servers #1242

erezrokah opened this issue Sep 15, 2020 · 6 comments · Fixed by #5005
Labels
area: command: dev area: frameworks type: bug code to address defects in shipped code

Comments

@erezrokah
Copy link
Contributor

erezrokah commented Sep 15, 2020

Describe the bug

The following rule is not applied for non static servers (when a framework is detected):

/* /index.html 200

To Reproduce

Steps to reproduce the behaviour:

  1. Run git clone https://github.com/11ty/eleventy-base-blog.git test-project
  2. cd test-project
  3. npm install
  4. rm 404.md (this is important so 11ty won't redirect to a custom error page)
  5. echo "/* /index.html 200" > _redirects
  6. Run BROWSER=none netlify dev
  7. Visit http://localhost:8888/test

See that you get an error from 11ty Cannot GET /test/index.htm

Configuration

  System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.67 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.9.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  npmGlobalPackages:
    netlify-cli: 2.63.2

Expected behavior

The index.html file content should be returned.

Additional context

Related to the discussion here #794 (comment) and to #810

The following does work:

/* /index.html 200!
/* /index.html 302

I believe the test here passes since create-react-app re-routes unknown routes to the index page. Meaning the redirect is handled in create-react-app.

The solution is to request the resource from the framework server - if it returns 404 redirect, otherwise don't redirect.

@warmbowski
Copy link

Just came across this on a project uses webpack-dev-server for local dev with a _redirects created via netlify-webpack-plugin. Working around by relying on redundant redirects in netlify.toml file for now, just so dev works properly. (this is in a monorepo, so ideally individual apps in the monorepo will have their own individual _redirects). If it helps, I do see the content of the redirects file via http://localhost:8888/_redirects.

@csvn
Copy link

csvn commented Feb 15, 2021

I think I've run into this issue too. I get Cannot GET /foo/index.htm for any paths I try out. Below is the configuration I'm using.

# netlify.toml
[dev]
  framework = "#custom"
  command = "npm run serve"
  targetPort = 8080
  port = 3000
  publish = "dist"
  autoLaunch = false
// package.json
    "serve": "npx @11ty/eleventy --serve",
# _redirects
/*    /index.html   200

@rjdusk
Copy link

rjdusk commented Apr 14, 2021

I too have also run into this issue, or something very similar. I get Cannot GET /bizz/index.htm on this redirect setup.

# netlify.toml
[dev]
  framework = "#custom"
  command = "npm run dev"
  publish = "dist"
  targetPort = 8081
  port = 8888

[[redirects]]
  from = "/bizz"
  to = "/about"
  status = 404

My npm run dev looks like this

ELEVENTY_ENV=development npx @11ty/eleventy --config=.eleventy.config.js --serve --port=8081 & webpack --watch --progress --config=node_modules/laravel-mix/setup/webpack.config.js

Does anyone have any clues as to what's going on with this problem? Thanks

@olearycrew
Copy link

I'm having this same issue with Svelte and svelte-navigator.

# netlify.toml

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

"scripts": {

   "dev": "npm run dev:rollup",

}

@andystevenson
Copy link

I have a simple 404 redirect which fails locally but works if deployed.

[[redirects]]
  from = "*"
  to = "/not-found"
  status = 404

This is a direct lift from @philhawksworth demo.

Clone https://github.com/andystevenson/wwsc.club to witness the problem.

@tinfoil-knight
Copy link
Contributor

tinfoil-knight commented Aug 5, 2022

For static sites (without any detected framework), the URL is re-written here:

cli/src/utils/proxy.js

Lines 243 to 251 in 73d9a6e

const destStaticFile = await getStatic(dest.pathname, options.publicFolder)
let statusValue
if (match.force || (!staticFile && ((!options.framework && destStaticFile) || isInternal(destURL)))) {
req.url = destStaticFile ? destStaticFile + dest.search : destURL
const { status } = match
statusValue = status
console.log(`${NETLIFYDEVLOG} Rewrote URL to`, req.url)
}

This doesn't happen when the options.framework value is present which might be causing the issue.

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

Successfully merging a pull request may close this issue.

7 participants