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 /// A cookie that goes out with the SSR fetches to this server's own origin, f. ex. the session:
61 /// `--ssr-fetch-cookie session`
62 ///
63 /// (default: all of them. Once one is named the others stay behind, and a visitor with only
64 /// those is rendered as a guest, which a cache on the way may keep)
65 #[arg(long)]
66 pub ssr_fetch_cookie: Vec<String>,
67
68 /// Indent the server-rendered HTML, to read it in the page source
69 ///
70 /// (the indentation is whitespace between elements: until the app starts, it shows as gaps
71 /// between inline ones, which hydration then takes out)
72 #[arg(long, default_value_t = {false})]
73 pub pretty_html: bool,
74
75 /// Disable gzip/brotli/zstd compression of served responses
76 ///
77 /// (useful behind a proxy or CDN that already compresses)
78 #[arg(long, default_value_t = {false})]
79 pub disable_compression: bool,
80
81 /// Compress the wasm, `wasm_run.js` and other text files of the build with brotli at its
82 /// highest level once, at startup, for the browsers that accept brotli
83 ///
84 /// (about a quarter smaller than compressing each response, for about a second of startup
85 /// per megabyte)
86 #[arg(long, default_value_t = {false})]
87 pub precompress: bool,
88
89 /// Number of threads to use for processing requests
90 ///
91 /// (default: number of CPU cores, 2 for watch mode)
92 #[arg(long)]
93 pub threads: Option<usize>,
94}