diff --git a/crates/collab/src/api.rs b/crates/collab/src/api.rs index 336db95e5e..62dc5f0dfd 100644 --- a/crates/collab/src/api.rs +++ b/crates/collab/src/api.rs @@ -1,5 +1,5 @@ pub mod events; -mod extensions; +pub mod extensions; use crate::{ auth, @@ -33,7 +33,6 @@ pub fn routes(rpc_server: Option>, state: Arc) -> Rou .route("/rpc_server_snapshot", get(get_rpc_server_snapshot)) .route("/contributors", get(get_contributors).post(add_contributor)) .route("/contributor", get(check_is_contributor)) - .merge(extensions::router()) .layer( ServiceBuilder::new() .layer(Extension(state)) diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index a29158337b..6175c7fb32 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -40,7 +40,16 @@ async fn main() -> Result<()> { run_migrations().await?; } Some("serve") => { - let is_api_only = args.next().is_some_and(|arg| arg == "api"); + let (is_api, is_collab) = if let Some(next) = args.next() { + (next == "api", next == "collab") + } else { + (true, true) + }; + if !is_api && !is_collab { + Err(anyhow!( + "usage: collab " + ))?; + } let config = envy::from_env::().expect("error loading config"); init_tracing(&config); @@ -52,7 +61,7 @@ async fn main() -> Result<()> { let listener = TcpListener::bind(&format!("0.0.0.0:{}", state.config.http_port)) .expect("failed to bind TCP listener"); - let rpc_server = if !is_api_only { + let rpc_server = if is_collab { let epoch = state .db .create_server(&state.config.zed_environment) @@ -66,8 +75,7 @@ async fn main() -> Result<()> { None }; - // TODO: Once we move the extensions endpoints to run inside `api` service, move the background task as well. - if !is_api_only { + if is_api { fetch_extensions_from_blob_store_periodically(state.clone(), Executor::Production); } @@ -80,6 +88,7 @@ async fn main() -> Result<()> { Router::new() .route("/", get(handle_root)) .route("/healthz", get(handle_liveness_probe)) + .merge(collab::api::extensions::router()) .merge(collab::api::events::router()) .layer(Extension(state.clone())), ) @@ -120,7 +129,9 @@ async fn main() -> Result<()> { .await?; } _ => { - Err(anyhow!("usage: collab "))?; + Err(anyhow!( + "usage: collab " + ))?; } } Ok(()) diff --git a/crates/extension/src/extension_store.rs b/crates/extension/src/extension_store.rs index 7857e088b6..7bd3768a87 100644 --- a/crates/extension/src/extension_store.rs +++ b/crates/extension/src/extension_store.rs @@ -1,7 +1,6 @@ use anyhow::{anyhow, bail, Context as _, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; -use client::ClientSettings; use collections::{BTreeMap, HashSet}; use fs::{Fs, RemoveOptions}; use futures::channel::mpsc::unbounded; @@ -13,7 +12,6 @@ use language::{ }; use parking_lot::RwLock; use serde::{Deserialize, Serialize}; -use settings::Settings as _; use std::cmp::Ordering; use std::{ ffi::OsStr, @@ -22,7 +20,7 @@ use std::{ time::Duration, }; use theme::{ThemeRegistry, ThemeSettings}; -use util::http::AsyncBody; +use util::http::{AsyncBody, ZedHttpClient}; use util::TryFutureExt; use util::{http::HttpClient, paths::EXTENSIONS_DIR, ResultExt}; @@ -57,7 +55,7 @@ pub enum ExtensionStatus { pub struct ExtensionStore { manifest: Arc>, fs: Arc, - http_client: Arc, + http_client: Arc, extensions_dir: PathBuf, extensions_being_installed: HashSet>, extensions_being_uninstalled: HashSet>, @@ -113,7 +111,7 @@ actions!(zed, [ReloadExtensions]); pub fn init( fs: Arc, - http_client: Arc, + http_client: Arc, language_registry: Arc, theme_registry: Arc, cx: &mut AppContext, @@ -145,7 +143,7 @@ impl ExtensionStore { pub fn new( extensions_dir: PathBuf, fs: Arc, - http_client: Arc, + http_client: Arc, language_registry: Arc, theme_registry: Arc, cx: &mut ModelContext, @@ -224,14 +222,12 @@ impl ExtensionStore { search: Option<&str>, cx: &mut ModelContext, ) -> Task>> { - let url = format!( - "{}/{}{query}", - ClientSettings::get_global(cx).server_url, - "api/extensions", + let url = self.http_client.zed_api_url(&format!( + "/extensions{query}", query = search .map(|search| format!("?filter={search}")) .unwrap_or_default() - ); + )); let http_client = self.http_client.clone(); cx.spawn(move |_, _| async move { let mut response = http_client.get(&url, AsyncBody::empty(), true).await?; @@ -264,10 +260,9 @@ impl ExtensionStore { cx: &mut ModelContext, ) { log::info!("installing extension {extension_id} {version}"); - let url = format!( - "{}/api/extensions/{extension_id}/{version}/download", - ClientSettings::get_global(cx).server_url - ); + let url = self + .http_client + .zed_api_url(&format!("/extensions/{extension_id}/{version}/download")); let extensions_dir = self.extensions_dir(); let http_client = self.http_client.clone();