-
Notifications
You must be signed in to change notification settings - Fork 53
[WIP] Add support for skew protection #746
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
base: main
Are you sure you want to change the base?
Conversation
|
commit: |
2356748
to
0a6f2dd
Compare
0a6f2dd
to
18ba05a
Compare
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 took a really quick look for now, will make a proper review later
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 think this is looking pretty good on my initial read though. Going to have another look later on as well.
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 think this looks good and the logic makes sense to me.
It might be nice for us to look at having an e2e that runs against a deployment at some point in the future, for testing features like this.
4c21542
to
471111c
Compare
packages/cloudflare/src/cli/build/open-next/compile-skew-protection.ts
Outdated
Show resolved
Hide resolved
packages/cloudflare/src/cli/build/open-next/compile-skew-protection.ts
Outdated
Show resolved
Hide resolved
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.
LGTM
Thanks for the review @sommeeeer ! |
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.
Just a few nits/question, other than that LGTM
packages/cloudflare/src/cli/build/open-next/compile-skew-protection.spec.ts
Outdated
Show resolved
Hide resolved
* @param paths The list of path | ||
* @returns The root node of the tree | ||
*/ | ||
export function filesToTree(paths: string[]): FolderNode { |
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 think in the future here, we should create glob pattern whenever we can to avoid having a too big FolderNode
. This could grow quite big if people have a lot of assets
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'll create a follow up issue for that.
packages/cloudflare/src/cli/build/open-next/compile-skew-protection.ts
Outdated
Show resolved
Hide resolved
* @param options Options to pass to `getPlatformProxy`, i.e. to set the environment | ||
* @returns the env vars | ||
*/ | ||
export async function getEnvFromPlatformProxy(options: GetPlatformProxyOptions) { |
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 think we should have only one instance of this, that we spawn at the beginning and that we dispose at the end. It's a bit wasteful to launch multiple workerd process.
And once we have support for remote bindings here, we could reuse it to populate the cache directly (which should be way faster)
client, | ||
accountId, | ||
afterTimeMs = new Date().getTime() - MAX_VERSION_AGE_DAYS * 24 * 3600 * 1000, | ||
maxNumberOfVersions = MAX_NUMBER_OF_VERSIONS, |
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 think this one should be overridable
path = path.slice(basePath.length); | ||
} | ||
if (path.startsWith("/_next/static/") || isFileInTree(path, __CF_ASSETS_TREE__)) { | ||
return assets.fetch(request); |
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.
Does this one respect the _headers
file ?
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.
It should but I'll test that
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.
Actually it doesn't, see https://developers.cloudflare.com/workers/static-assets/headers/#custom-headers
…ction.ts Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
2f1f47b
to
45edc9f
Compare
There are 2 main files in this PR:
packages/cloudflare/src/cli/commands/skew-protection.ts
(build time)This builds a mapping from
deploymentId
to the worker version at build time.Note that because the worker you are building has no version yet, "current" is used instead.
packages/cloudflare/src/cli/templates/skew-protection.ts
(runtime)At runtime, if a particular version is requested and it is present in the mapping,
we'll fetch the result from a preview URL with a hostname of
<version>-<worker_name>.<domain>.workers.dev
How to use it:
cloudflare.skewProtectionEnabled
totrue
in your OpenNext configpackages/cloudflare/src/api/cloudflare-context.ts
deployementId
- you can use thegetDeploymentId()
helperrun_worker_first
totrue
Docs PR opennextjs/docs#164
TODO: