cli
cli copied to clipboard
Bug: re-write rules are not applied for non static servers
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:
- Run
git clone https://github.com/11ty/eleventy-base-blog.git test-project
-
cd test-project
-
npm install
-
rm 404.md
(this is important so 11ty won't redirect to a custom error page) -
echo "/* /index.html 200" > _redirects
- Run
BROWSER=none netlify dev
- 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 https://github.com/netlify/cli/issues/794#issuecomment-610619793 and to https://github.com/netlify/cli/pull/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.
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
.
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
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
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",
}
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.
For static sites (without any detected framework), the URL is re-written here:
https://github.com/netlify/cli/blob/73d9a6e9c00ba5b056ee27406b0f4e107c192622/src/utils/proxy.js#L243-L251
This doesn't happen when the options.framework
value is present which might be causing the issue.