Skip to main content

vertigo_cli/serve/
serve_opts.rs

1use clap::Args;
2
3use crate::commons::models::CommonOpts;
4use crate::commons::parse_key_val;
5
6#[derive(Args, Clone, Debug)]
7pub struct ServeOpts {
8    #[clap(flatten)]
9    pub inner: ServeOptsInner,
10    #[clap(flatten)]
11    pub common: CommonOpts,
12}
13
14#[derive(Args, Clone, Debug)]
15pub struct ServeOptsInner {
16    #[arg(long, default_value_t = {"127.0.0.1".into()})]
17    pub host: String,
18    #[arg(long, default_value_t = {4444})]
19    pub port: u16,
20
21    /// sets up proxy: `--proxy /path=http://domain.com/path`
22    ///
23    /// Websockets under the path go through as well.
24    #[arg(long, value_parser = parse_key_val::<String, String>)]
25    pub proxy: Vec<(String, String)>,
26
27    /// Define a mount point for the app in public url.
28    ///
29    /// (For example an nginx's location in which proxy_pass to the app was defined)
30    #[arg(long, default_value_t = {"/".to_string()})]
31    pub mount_point: String,
32
33    /// Setting the parameters `--env api=http://domain.com/api --env api2=http://domain.com/api2`
34    #[arg(long, value_parser = parse_key_val::<String, String>)]
35    pub env: Vec<(String, String)>,
36
37    /// Whether to start downloading and compiling WASM while the page loads, instead of after
38    /// (at low priority, so images and styles take precedence)
39    #[arg(long, default_value_t = {false})]
40    pub wasm_preload: bool,
41
42    /// Disable hydration on page load (will re-create DOM instead of claiming existing nodes from SSR)
43    #[arg(long, default_value_t = {false})]
44    pub disable_hydration: bool,
45
46    /// Origin for resolving relative fetch URLs during SSR: `--ssr-fetch-base http://127.0.0.1:8080`
47    ///
48    /// (default: this server's address)
49    #[arg(long)]
50    pub ssr_fetch_base: Option<String>,
51
52    /// A cookie the app may read during SSR too, f. ex. the language the user picked:
53    /// `--ssr-cookie lang --ssr-cookie theme`
54    ///
55    /// (only one the browser shows the app too, not `HttpOnly`: the server would render what the
56    /// browser can't)
57    #[arg(long)]
58    pub ssr_cookie: Vec<String>,
59
60    /// Indent the server-rendered HTML, to read it in the page source
61    ///
62    /// (the indentation is whitespace between elements: until the app starts, it shows as gaps
63    /// between inline ones, which hydration then takes out)
64    #[arg(long, default_value_t = {false})]
65    pub pretty_html: bool,
66
67    /// Disable gzip/brotli/zstd compression of served responses
68    ///
69    /// (useful behind a proxy or CDN that already compresses)
70    #[arg(long, default_value_t = {false})]
71    pub disable_compression: bool,
72
73    /// Compress the wasm, `wasm_run.js` and other text files of the build with brotli at its
74    /// highest level once, at startup, for the browsers that accept brotli
75    ///
76    /// (about a quarter smaller than compressing each response, for about a second of startup
77    /// per megabyte)
78    #[arg(long, default_value_t = {false})]
79    pub precompress: bool,
80
81    /// Number of threads to use for processing requests
82    ///
83    /// (default: number of CPU cores, 2 for watch mode)
84    #[arg(long)]
85    pub threads: Option<usize>,
86}