-
Notifications
You must be signed in to change notification settings - Fork 407
server: refactor redirects so they're more declarative #943
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
server: refactor redirects so they're more declarative #943
Conversation
|
Looks like an unrelated lint issue popped up in a file I didn't change. |
|
@fabiosantoscode okay, this is a good ticket, but we should handle it in a different way. Let's discuss this on Discord. |
5a5d2c6 to
cedd079
Compare
|
@fabiosantoscode check the comment re the 301 vs 303, let's try to wrap it as a worker for the Cloudflare. Move redirects.js into redirects.json and try to make it way more declarative. |
|
@shcheklein do you mean that you want me to make this a worker right now? I couldn't find any existing cloudflare workers on this repository. |
cedd079 to
34bbf4b
Compare
|
@shcheklein I've addressed the part of the feedback I'm sure about, by making some redirects permanent and others not. I've also changed the file to JSON and used an approach that will be familiar to anyone who knows how
Please let me know if you'd like me to create a service worker which could be used in the browser or cloudflare, or if the changes I made were only in anticipation of moving to cloudflare workers. Cheers! ⛄ |
|
Is it me or codeclimate is being extremely picky? |
|
@fabiosantoscode yes, pay reasonable attention to it, no need to fix all complaints :) |
|
Good stuff! Next steps here:
|
|
@shcheklein So an array of space-separated strings then? The tests will be cool to write, I'll get on it. |
|
@shcheklein I've used a bunch of spaces to align the targets and make the JSON file easier to read, even if it's wider. I've had to create a |
|
I mean, I didn't have to but it seemed nicer. |
shcheklein
left a comment
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.
awesome! just a few minor comments/requests for improvement, and let's wait for @jorgeorpinel to have a second look.
shcheklein
left a comment
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.
looks awesome! let's wait for @jorgeorpinel to take a look and merge and test after that. I wonder if there is also a service somewhere to setup that will be pinging website for predefined URLs and check if they behave properly?
|
@shcheklein this sounds like something pingdom can do, but I'm not sure we can check where the redirect goes to. We can also use circleCI to run periodic tests against production. We can reuse the redirects tests I added, but add an environmental variable that tells them to hit production. We can add more tests like this later. Another thing that might work is google cloud platform uptime checks. You can poll a certain URL (like man.dvc.org/add) and make sure the response content contains or matches a certain string. However this is only feasible if we add a message explaining the redirect containing a redirect link target as the redirect response body. Additionally, another similar check can check for the uptime of the blog itself. And these uptime checks can ping people through e-mail, SMS and other media. |
|
merging this, if we hit any issue will be solving as we go. Takes too long otherwise. |
| const next = require('next') | ||
|
|
||
| const { getItemByPath } = require('./src/utils/sidebar') | ||
| const { getRedirect } = require('./src/redirects.js') |
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.
Should this live in src/utils @fabiosantoscode @shcheklein ? Thanks
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.
yep, we can move them .. move redirects-list to the root porbably
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.
Will move and PR
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.
Thanks!
|
My last comment here is that I personally find the space separation in the JSON file strange. A normal JSON file with an array of arrays or something like that should work as well and easier to read? Let me review the new PR and will see if this comment is still valid. I may also just push some suggested changes myself if needed. Thanks |
|
@jorgeorpinel we had an iteration like this and I didn't like it (not sure about @fabiosantoscode :) ) - it's 1000 lines vs 10. It's way easier to read line by line. It's very regular format for redirects files - one rule a line. There should be very strong reasons to complicate this. |
This places redirects in a separate file and attempts to simplify them.
I've identified two kinds of redirects, a redirect based on the host, and a redirect based on pathname. I've used classes but I'm not married to that approach.
I've added cache-control: no-cache to all redirects and they're all 303's, but this approach can be extended to include some options specific to each redirect as an options object in the constructor.
Fixes #757
Disregard the recommendations below if you use Edit on GitHub button to improve the docs in place.
❗ Please read the guidelines in the Contributing to the Documentation list if you make any substantial changes to the documentation or JS engine.
🐛 Please make sure to mention
Fix #issue(if applicable) in the description of the PR. This enables GitHub to link the PR to the corresponding bug and close it automatically when PR is merged.Thank you for the contribution - we'll try to review and merge it as soon as possible. 🙏