-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add support for additional/custom Netlify redirect rule criteria #2890
Add support for additional/custom Netlify redirect rule criteria #2890
Conversation
Deploy preview ready! Built with commit 23f1527 |
Deploy preview ready! Built with commit 23f1527 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth treating the key/value pairs as an array and joining them with ,
:
keyValuePairs: {
Language: ['zh', 'ja'],
},
Right now you'd need to know to combine them with a single comma with no space, which is a leaky abstraction:
keyValuePairs: {
Language: 'zh,ja',
},
I think "settings" or "config" is a good name for them. "keyValuePairs" is pretty generic - It explains the data type rather than the purpose 😄
const pieces = [ | ||
redirect.fromPath, | ||
redirect.toPath, | ||
redirect.isPermanent ? 301 : 302, // Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a side note, for a future enhancement it would be good to support 200
, which serves the file without redirecting. A use case is for a simple single-page app where you want all URLs to go to the one actual HTML page. Also, 404
, which serves a custom 404 page for the URL (returns the provided HTML file with a 404
status code). Maybe instead of a boolean isRedirect
, this could be a mode
enum with 'temporaryRedirect'
, 'permanentRedirect'
, 'internalRedirect'
(200) or 'fileNotFound'
? Totally outside the scope of this PR though :)
redirect.isPermanent ? 301 : 302, // Status | ||
] | ||
|
||
const keyValuePairs = redirect.keyValuePairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this settings
?
Hm. Maybe. I think string-to-string mapping is nice. The plug-in specifically warns if you provide a value with a space in it, FWIW. As for "leaky" - I think it's reasonable for users to read the documentation if they're writing redirect rules 😉
Naming is hard. 🤔 This could be used for lots of things - language, country, role, etc. - so I opted for a name that at least described the shape of the data. I think "settings" and "config" is even more vague than "keyValuePairs". Neither describes the purpose but at least the latter hints at the structure. I dunno. This is subjective. I don't feel super strongly about it. I think of the whole data structure that's passed to the method as "settings" or "config" though. |
Okay, I'm convinced (on both points) 😛 What about "extraData" instead of "keyValuePairs"? oh man naming things is so hard |
Agreed! 😆 I guess I like "extraData" well enough. It's still pretty vague. I found myself wanting to just use
But I'm not sure this is intuitive. |
Oh yeah, that's pretty nice. The other option could be to pass two arguments to
That looks kinda ugly though. |
TBH the main reason I didn't use |
I think I'm going to change it to Thanks for the discussion! |
Sounds good! :D |
1fef813
to
8cc4ab8
Compare
Looks like "AWS CodeBuild" is failing but I don't have permissions to see why. 😄 |
Eh sorry about that — it's a WIP thing and doesn't mean anything right now. Rolling out soon though some super cool new integration testing :-) It'll be building/testing every example site on every commit + a bunch of community sites including reactjs.org! |
That's really exciting 😁 |
For the repl tests & appveyor — I put up this PR #2908 We've faced this issue a few times already 🙄 |
Great! I'll back out that single commit then. |
Thanks! |
Thank you, as usual
|
The Netlify redirects documentation has a section titled "GeoIP and Language-based redirects" that outlines how to specify country and language based redirect rules. This PR adds support for these by adding
...rest
params to the redirect action and consuming them in thegatsby-plugin-netlify
plug-in.For example, given the following calls:
The updated plug-in will now generate the following
_redirects
content:The plug-in also warns about values with spaces in them (since at least the Netlify plug-in doesn't support them). For example:
Will log the following warning:
Note that this PR will also add the ability to support additional Netlify redirect rules like "Role".