wick_config/config/app_config/triggers/http/
proxy_router.rs1use std::collections::HashMap;
2use std::path::Path;
3
4use wick_asset_reference::AssetReference;
5use wick_packet::RuntimeConfig;
6
7use super::index_to_router_id;
8use super::middleware::expand_for_middleware_components;
9use crate::config::bindings::BoundIdentifier;
10use crate::config::template_config::Renderable;
11use crate::config::{self, Binding, ImportDefinition};
12use crate::error::ManifestError;
13
14#[derive(
15 Debug, Clone, derive_builder::Builder, derive_asset_container::AssetManager, property::Property, serde::Serialize,
16)]
17#[asset(asset(AssetReference))]
18#[property(get(public), set(private), mut(disable))]
19
20pub struct ProxyRouterConfig {
21 #[asset(skip)]
23 #[property(get(disable))]
24 pub(crate) path: String,
25 #[property(get(disable))]
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub(crate) middleware: Option<super::middleware::Middleware>,
29 #[asset(skip)]
31 pub(crate) url: BoundIdentifier,
32 #[asset(skip)]
34 pub(crate) strip_path: bool,
35}
36
37impl Renderable for ProxyRouterConfig {
38 fn render_config(
39 &mut self,
40 source: Option<&Path>,
41 root_config: Option<&RuntimeConfig>,
42 env: Option<&HashMap<String, String>>,
43 ) -> Result<(), ManifestError> {
44 self.middleware.render_config(source, root_config, env)
45 }
46}
47
48impl super::WickRouter for ProxyRouterConfig {
49 fn middleware(&self) -> Option<&super::Middleware> {
50 self.middleware.as_ref()
51 }
52
53 fn middleware_mut(&mut self) -> Option<&mut super::Middleware> {
54 self.middleware.as_mut()
55 }
56
57 fn path(&self) -> &str {
58 &self.path
59 }
60}
61
62pub(crate) fn process_runtime_config(
63 trigger_index: usize,
64 index: usize,
65 router_config: &mut ProxyRouterConfig,
66 bindings: &mut Vec<Binding<ImportDefinition>>,
67) -> Result<(), ManifestError> {
68 expand_for_middleware_components(trigger_index, index, router_config, bindings)?;
69 let router_component = config::ComponentDefinition::Native(config::components::NativeComponent {});
70 let router_binding = config::Binding::new(
71 index_to_router_id(trigger_index, index),
72 ImportDefinition::component(router_component),
73 );
74
75 bindings.push(router_binding);
76 Ok(())
77}