mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-22 08:02:19 +00:00
feat: support wildcards in http routes (#6927)
This commit is contained in:
@@ -62,7 +62,9 @@ pub async fn increase_trigger_version(tx: &mut PgConnection) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn generate_route_path_key(route_path: &str) -> String {
|
||||
ROUTE_PATH_KEY_RE.replace_all(route_path, "/*").to_string()
|
||||
ROUTE_PATH_KEY_RE
|
||||
.replace_all(route_path, "${1}${2}key")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub async fn route_path_key_exists(
|
||||
@@ -322,7 +324,7 @@ async fn check_if_route_exist(
|
||||
workspace_id: &str,
|
||||
trigger_path: Option<&str>,
|
||||
) -> Result<String> {
|
||||
let route_path_key = ROUTE_PATH_KEY_RE.replace_all(&config.route_path, ":key");
|
||||
let route_path_key = generate_route_path_key(&config.route_path);
|
||||
|
||||
let exists = route_path_key_exists(
|
||||
&route_path_key,
|
||||
@@ -340,7 +342,7 @@ async fn check_if_route_exist(
|
||||
));
|
||||
}
|
||||
|
||||
Ok(route_path_key.into_owned())
|
||||
Ok(route_path_key)
|
||||
}
|
||||
|
||||
pub struct HttpTrigger;
|
||||
|
||||
@@ -192,8 +192,9 @@ impl<'de> Deserialize<'de> for HttpConfigRequest {
|
||||
|
||||
// Regex patterns for route validation
|
||||
lazy_static::lazy_static! {
|
||||
static ref ROUTE_PATH_KEY_RE: regex::Regex = regex::Regex::new(r"/?:[-\w]+").unwrap();
|
||||
static ref VALID_ROUTE_PATH_RE: regex::Regex = regex::Regex::new(r"^:?[-\w]+(/:?[-\w]+)*$").unwrap();
|
||||
// Matches named params like :id or wildcards like :* or *
|
||||
static ref ROUTE_PATH_KEY_RE: regex::Regex = regex::Regex::new(r"(/)?(:|\*)[-\w]+").unwrap();
|
||||
static ref VALID_ROUTE_PATH_RE: regex::Regex = regex::Regex::new(r"^(\*[-\w]+$|:?[-\w]+)(/(\*[-\w]+$|:?[-\w]+))*$").unwrap();
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@@ -54,7 +54,11 @@
|
||||
clearTimeout(validateTimeout)
|
||||
}
|
||||
validateTimeout = setTimeout(async () => {
|
||||
if (!routePath || !method || !/^:?[-\w]+(\/:?[-\w]+)*$/.test(routePath)) {
|
||||
if (
|
||||
!routePath ||
|
||||
!method ||
|
||||
!/^(\*[-\w]+$|:?[-\w]+)(\/(\*[-\w]+$|:?[-\w]+))*$/.test(routePath)
|
||||
) {
|
||||
routeError = 'Endpoint not valid'
|
||||
} else if (await routeExists(routePath, method, workspaced_route)) {
|
||||
routeError = 'Endpoint already taken'
|
||||
@@ -140,7 +144,9 @@
|
||||
bind:value={route_path}
|
||||
error={routeError !== ''}
|
||||
/>
|
||||
<div class="text-2xs text-secondary"> ':myparam' for path params </div>
|
||||
<div class="text-2xs text-secondary">
|
||||
Use ':myparam' for path params and '*mywildcard' for wildcards
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user