Skip to content

Commit

Permalink
Merge pull request #266 from nyannyacha/fix-sb-ua
Browse files Browse the repository at this point in the history
fix: make the runtime user agent respect the convention
  • Loading branch information
laktek authored Feb 13, 2024
2 parents 705db6e + 0640f70 commit d6c7833
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions crates/base/src/deno_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use deno_tls::rustls::RootCertStore;
use deno_tls::RootCertStoreProvider;
use futures_util::future::poll_fn;
use log::{error, trace};
use once_cell::sync::OnceCell;
use once_cell::sync::{Lazy, OnceCell};
use sb_core::conn_sync::ConnSync;
use sb_core::util::sync::AtomicFlag;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -80,6 +80,14 @@ fn get_error_class_name(e: &AnyError) -> &'static str {
}

pub static MAYBE_DENO_VERSION: OnceCell<String> = OnceCell::new();
static SUPABASE_UA: Lazy<String> = Lazy::new(|| {
let deno_version = MAYBE_DENO_VERSION.get().map(|it| &**it).unwrap_or("1.0.0");
let supabase_version = option_env!("GIT_V_TAG").unwrap_or("0.1.0");
format!(
"Deno/{} (variant; SupabaseEdgeRuntime/{})",
deno_version, supabase_version
)
});

pub struct DenoRuntime {
pub js_runtime: JsRuntime,
Expand Down Expand Up @@ -108,7 +116,6 @@ impl DenoRuntime {
..
} = opts;

let user_agent = "supabase-edge-runtime".to_string();
let base_dir_path = std::env::current_dir().map(|p| p.join(&service_path))?;
let base_url = Url::from_directory_path(&base_dir_path).unwrap();

Expand Down Expand Up @@ -250,12 +257,12 @@ impl DenoRuntime {
deno_webgpu::deno_webgpu::init_ops(),
deno_canvas::deno_canvas::init_ops(),
deno_fetch::deno_fetch::init_ops::<Permissions>(deno_fetch::Options {
user_agent: user_agent.clone(),
user_agent: SUPABASE_UA.clone(),
root_cert_store_provider: Some(root_cert_store_provider.clone()),
..Default::default()
}),
deno_websocket::deno_websocket::init_ops::<Permissions>(
user_agent,
SUPABASE_UA.clone(),
Some(root_cert_store_provider.clone()),
None,
),
Expand Down
2 changes: 1 addition & 1 deletion crates/sb_core/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ globalThis.bootstrapSBEdge = (opts, isUserWorker, isEventsWorker, edgeRuntimeVer
ObjectDefineProperty(globalThis, 'Deno', readOnly(denoOverrides));

setNumCpus(1); // explicitly setting no of CPUs to 1 (since we don't allow workers)
setUserAgent('Supabase Edge Runtime');
setUserAgent(`Deno/${globalThis.DENO_VERSION} (variant; SupabaseEdgeRuntime/${globalThis.SUPABASE_VERSION})`);
setLanguage('en');

if (isUserWorker) {
Expand Down

0 comments on commit d6c7833

Please sign in to comment.