wrangler/commands/dev/gcs/
setup.rs

1use crate::commands::dev::ServerConfig;
2use crate::preview::upload;
3use crate::settings::global_user::GlobalUser;
4use crate::settings::toml::Target;
5
6use anyhow::Result;
7use uuid::Uuid;
8
9/// generate a unique uuid that lasts the entirety of the
10/// `wrangler dev` session
11pub(super) fn get_session_id() -> Result<String> {
12    Ok(Uuid::new_v4().to_simple().to_string())
13}
14
15/// upload the script to the Workers API, and combine its response
16/// with the session id to get the preview ID
17///
18/// this is used when sending requests to the Workers Runtime
19/// so it executes the correct Worker
20pub fn get_preview_id(
21    mut target: Target,
22    user: Option<GlobalUser>,
23    server_config: &ServerConfig,
24    session_id: &str,
25    verbose: bool,
26) -> Result<String> {
27    // setting sites_preview to `true` would print a message to the terminal
28    // directing the user to open the browser to view the output
29    // this message makes sense for `wrangler preview` but not `wrangler dev`
30    let sites_preview = false;
31    let script_id = upload(&mut target, user.as_ref(), sites_preview, verbose)?;
32    Ok(format!(
33        "{}{}{}{}",
34        &script_id,
35        session_id,
36        server_config.host.is_https() as u8,
37        server_config.host
38    ))
39}