-
Notifications
You must be signed in to change notification settings - Fork 400
Add application redirects + vary headers #828
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 application redirects + vary headers #828
Conversation
da6e24f
to
42e1776
Compare
src/amo/routes.js
Outdated
<Route path="/(:lang/)" component={App}> | ||
<Route path="/:lang/:application" component={App}> | ||
<IndexRoute component={Home} /> | ||
<Route path="addon/:slug(/)" component={DetailPage} /> |
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.
This can now have the optional trailing slash removed having move to a middleware.
92fbc13
to
9233bf2
Compare
src/core/i18n/utils.js
Outdated
* Looks up the language from the router renderProps. | ||
* When that fails fall-back to accept-language. | ||
* Check validity of language: | ||
* - If invalid fall-back to accept-language. |
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.
nit: comma after invalid
I need to add a test to make sure query strings aren't mangled in this process. |
src/core/server/base.js
Outdated
} catch (e) { | ||
log.info(dedent`Locale not found or required for locale: "${locale}". | ||
Falling back to default lang: "${config.get('defaultLang')}"`); | ||
log.info(`Locale not found or required for locale: "${locale}"`); |
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.
this sentence is hard for me to parse
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, I'll fix that up...
r+wc -- mostly nits but I think there is a bit of test duplication that won't be very helpful (it will just slow down the suite). |
97c66b4
to
8f7d708
Compare
@kumar303 - can you take a look at the last commit. I ended up needing to refactor some of the i18n utils to make them more clear. |
tests/client/core/test_utils.js
Outdated
describe('isValidClientApp', () => { | ||
const fakeConfig = new Map(); | ||
fakeConfig.set('validClientApplications', ['firefox', 'android']); | ||
// eslint-disable-next-line no-underscore-dangle |
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 just added this rule in #819 If you rebase on master you'll get it.
8f7d708
to
34232d5
Compare
For |
The new changes look good. r+wc |
34232d5
to
427da74
Compare
Clean-up and improve naming Fix review comments, delete duped tests and improve i18n utils Remove no-underscore-dangle comments
427da74
to
3cc8d2d
Compare
Fixes mozilla/addons#9763 and mozilla/addons#9762
This PR:
slashes are appended unless configured not to be. This is off for the disco pane since the URL in the pref doesn't end with a slash. (If we are going to need more control over this we'll need to think again) FWIW: AMO currently seems to mostly favour always adding a slash.NOTE: I updated and removed the slash handling for now. I think this is potentially better added separately if we want it.
The reason for moving to a middleware is because redirections need to happen for URLS that may not match the routes. If it's all done in react-router the redirects can only happen for matching routes. This also means the router prefix for lang and application don't have to be optional which also looks a bit nicer.
Like AMO the reason for having this in one piece of code is that the result is a single redirect. I added logic so vary headers are set only when headers are used for introspection. E.g. if an accept-language fall-back isn't used there won't be a vary on accept-language.
The redirection behaviour should match up to what AMO currently does e.g:
I'm still not sure if we should take the leading locale and application off the url at this point? That would mean react-router routes wouldn't need to care about locale or app at all. Either way we can consider that separately.
Adding user-agent header introspection to work out the correct application is to follow.