Skip to content

Commit

Permalink
cli: implement 'server of server' for a local web server
Browse files Browse the repository at this point in the history
Closes #168492

This implements @aeschli's 'server server' concept in a new
`code serve-web` command.

Command line args are similar to the standalone web server. The first
time a user hits that page, the latest version of the VS Code web server
will be downloaded and run. Thanks to Martin's previous PRs, all
resources the page requests are prefixed with `/<quality-<commit>`.

The latest release version is cached, but when the page is loaded again
and there's a new release, a the new server version will be downloaded
and started up.

Behind the scenes the servers all listen on named pipes/sockets and the
CLI acts as a proxy server to those sockets. Servers without connections
for an hour will be shut down automatically.
  • Loading branch information
connor4312 committed Aug 22, 2023
1 parent d0b14e8 commit e585723
Show file tree
Hide file tree
Showing 17 changed files with 753 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .vscode/shared.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Placeholders with the same ids are connected.
// Example:
"MSFT Copyright Header": {
"scope": "javascript,typescript,css",
"scope": "javascript,typescript,css,rust",
"prefix": [
"header",
"stub",
Expand Down
4 changes: 2 additions & 2 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ libc = "0.2.144"
tunnels = { git = "https://github.com/microsoft/dev-tunnels", rev = "2621784a9ad72aa39500372391332a14bad581a3", default-features = false, features = ["connections"] }
keyring = { version = "2.0.3", default-features = false, features = ["linux-secret-service-rt-tokio-crypto-openssl"] }
dialoguer = "0.10.4"
hyper = "0.14.26"
hyper = { version = "0.14.26", features = ["server", "http1", "runtime"] }
indicatif = "0.17.4"
tempfile = "3.5.0"
clap_lex = "0.5.0"
Expand Down
6 changes: 5 additions & 1 deletion cli/src/bin/code/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::process::Command;

use clap::Parser;
use cli::{
commands::{args, tunnels, update, version, CommandContext},
commands::{args, serve_web, tunnels, update, version, CommandContext},
constants::get_default_user_agent,
desktop, log,
state::LauncherPaths,
Expand Down Expand Up @@ -99,6 +99,10 @@ async fn main() -> Result<(), std::convert::Infallible> {
tunnels::command_shell(context!(), cs_args).await
}

Some(args::Commands::ServeWeb(sw_args)) => {
serve_web::serve_web(context!(), sw_args).await
}

Some(args::Commands::Tunnel(tunnel_args)) => match tunnel_args.subcommand {
Some(args::TunnelSubcommand::Prune) => tunnels::prune(context!()).await,
Some(args::TunnelSubcommand::Unregister) => tunnels::unregister(context!()).await,
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub mod args;
pub mod tunnels;
pub mod update;
pub mod version;
pub mod serve_web;
pub use context::CommandContext;
31 changes: 31 additions & 0 deletions cli/src/commands/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,42 @@ pub enum Commands {
/// Changes the version of the editor you're using.
Version(VersionArgs),

/// Runs a local web version of VS Code.
ServeWeb(ServeWebArgs),

/// Runs the control server on process stdin/stdout
#[clap(hide = true)]
CommandShell(CommandShellArgs),
}

#[derive(Args, Debug, Clone)]
pub struct ServeWebArgs {
/// Host to listen on, defaults to 'localhost'
#[clap(long)]
pub host: Option<String>,
/// Port to listen on. If 0 is passed a random free port is picked.
#[clap(long, default_value_t = 8000)]
pub port: u16,
/// A secret that must be included with all requests.
#[clap(long)]
pub connection_token: Option<String>,
/// Run without a connection token. Only use this if the connection is secured by other means.
#[clap(long)]
pub without_connection_token: bool,
/// If set, the user accepts the server license terms and the server will be started without a user prompt.
#[clap(long)]
pub accept_server_license_terms: bool,
/// Specifies the directory that server data is kept in.
#[clap(long)]
pub server_data_dir: Option<String>,
/// Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.
#[clap(long)]
pub user_data_dir: Option<String>,
/// Set the root path for extensions.
#[clap(long)]
pub extensions_dir: Option<String>,
}

#[derive(Args, Debug, Clone)]
pub struct CommandShellArgs {
/// Listen on a socket instead of stdin/stdout.
Expand Down
Loading

0 comments on commit e585723

Please sign in to comment.