This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 334
Prevent preview/dev for unauthenticated workers sites #1138
Comments
What do you think about this change as a way to handle? Current: Proposed: ...
fn unauthenticated_upload(target: &Target) -> Result<Preview, failure::Error> {
let create_address = "https://cloudflareworkers.com/script";
log::info!("address: {}", create_address);
// KV namespaces and Sites are not supported by the preview service unless you authenticate
// so we omit them and provide the user with a little guidance. We don't error out, though,
// because there are valid workarounds for this for testing purposes.
let script_upload_form = if target.kv_namespaces.is_some() {
message::warn(
"KV Namespaces are not supported in preview without setting API credentials and account_id",
);
let mut target = target.clone();
target.kv_namespaces = None;
upload::form::build(&target, None)?
}
// --- Check for and handle presence of a Site
else if target.site.is_some() {
message::warn(
"Sites are not supported in preview without setting API credentials and account_id",
);
let mut target = target.clone();
target.site = None;
upload::form::build(&target, None)?
}
// ---
else {
upload::form::build(&target, None)?
};
let client = http::client();
let res = client
.post(create_address)
.multipart(script_upload_form)
.send()?
.error_for_status()?;
let text = &res.text()?;
log::info!("Response from preview: {:#?}", text);
let preview: Preview =
serde_json::from_str(text).expect("could not create a script on cloudflareworkers.com");
Ok(preview)
}
... |
seems good to me @bradyjoslin 😄 |
Hey @bradyjoslin are you planning on making a PR with that change? I can do it if you would like |
Hi @jspspike - please feel free to run with the PR. Thanks for checking! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
We currently prevent
wrangler preview
if there are namespaces - let's extend that to if there are sitesThe text was updated successfully, but these errors were encountered: