-
-
Notifications
You must be signed in to change notification settings - Fork 25
Move API docs redirects to CloudFront #366
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
Changes from 1 commit
5b46ca9
1e619fa
3a3f48f
9a34488
9c56ad8
9e56b54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function handler(event) { | ||
var requestPath = event.request.uri | ||
var redirectUri = null | ||
|
||
if(requestPath.startsWith('/api/latest/')) { | ||
redirectUri = requestPath.replace('/api/latest/', '/api/${CRYSTAL_VERSION}/') | ||
} else if(requestPath.startsWith('/api/') && !(requestPath.startsWith('/api/0') || requestPath.startsWith('/api/1'))) { | ||
redirectUri = requestPath.replace('/api/', '/api/${CRYSTAL_VERSION}/') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: I think we also need to pass through paths with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current s3 setup, we also have the following redirects which we might want to incorporate into cloudfront:
Maybe they should all redirect directly to Then we could delete the files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they can all be 301 to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oohhh! Good catch. The S3 rules don't mention anything about My first instinct is to keep this function as simple as possible: move it to after the request went to S3, and only work with 404's (as we're doing now with S3); and keep the few redirects that @straight-shoota mentions that are files in the bucket (ie, not S3 "logic"). But if you have a strong reason to move all the logic to this function, I can do that too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was also expecting this function to go before S3. But I'm not determined on whether that's actually better or not. I suppose most legitimate requests should not hit a 404 anyway. So maybe it's more efficient to have the rewrite only after S3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. But the different versions are easily accessible from the version selector on each API doc page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant an internal doc to avoid situations where it's only in someone's 🧠. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah, we probably should write that down somewhere. Although the CI workflows also document what's happening. Btw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From CloudFront - Restrictions on all edge functions:
🤦 So we can't say "send the request to S3, and we'll do our thing if that fails" 😞 Don't know why they put this limitation in place, but it changes the framing of the function. We'll need to apply the redirects before trying to hit the bucket. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damn. Well, the rules are static and small. It's doable to hardcode them. |
||
|
||
if(redirectUri != null) { | ||
return { | ||
statusCode: 302, | ||
headers: { | ||
'location': { value: redirectUri } | ||
} | ||
} | ||
} | ||
|
||
return event.request | ||
} |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.