Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description_basic = "The route name_id format is invalid."
http_status = 400
---

# invalid_name_id
# Invalid Name ID

The name_id provided for the route is invalid. Route name_ids must be lowercase alphanumeric or dashes without repeating double dashes, and are limited to 16 characters.

Expand All @@ -22,4 +22,4 @@ Make sure your name_id:
### Examples

Invalid: `UPPERCASE-route`, `route--name`, `-route-name`, `route-name-`
Valid: `my-route`, `route-123`, `api-v2`
Valid: `my-route`, `route-123`, `api-v2`
78 changes: 32 additions & 46 deletions packages/toolchain/cli/src/util/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,55 +394,41 @@ async fn create_function_route(
route_tags: &HashMap<String, String>,
default_hostname: &str,
) -> Result<()> {
// Get route_subpaths and strip_prefix from config
let default_route_subpaths = function.route_subpaths.unwrap_or(true);
let default_strip_prefix = function.strip_prefix.unwrap_or(true);

// Loop until route creation succeeds
let mut route_created = false;
while !route_created {
let hostname = default_hostname.to_string();
let path = function.path();
let route_subpaths = default_route_subpaths;
let strip_prefix = default_strip_prefix;

// Prepare route body
let update_route_body = models::RoutesUpdateRouteBody {
hostname,
path,
route_subpaths,
strip_prefix,
target: Box::new(models::RoutesRouteTarget {
actors: Some(Box::new(models::RoutesRouteTargetActors {
selector_tags: route_tags.clone(),
})),
}),
};

// Create/update route
let result = apis::routes_api::routes_update(
&ctx.openapi_config_cloud,
&fn_name,
update_route_body.clone(),
Some(&ctx.project.name_id.to_string()),
Some(&environment.slug),
)
.await;

match result {
Result::Ok(_) => {
println!(
"Successfully created route: {}{}",
update_route_body.hostname, update_route_body.path
);
route_created = true;
}
Err(err) => {
eprintln!("Failed to create route: {}", err);
break;
}
}
}
let hostname = default_hostname.to_string();
let path = function.path();
let route_subpaths = default_route_subpaths;
let strip_prefix = default_strip_prefix;

// Prepare route body
let update_route_body = models::RoutesUpdateRouteBody {
hostname,
path,
route_subpaths,
strip_prefix,
target: Box::new(models::RoutesRouteTarget {
actors: Some(Box::new(models::RoutesRouteTargetActors {
selector_tags: route_tags.clone(),
})),
}),
};

// Create/update route
apis::routes_api::routes_update(
&ctx.openapi_config_cloud,
&fn_name,
update_route_body.clone(),
Some(&ctx.project.name_id.to_string()),
Some(&environment.slug),
)
.await?;

println!(
"Successfully created route: {}{}",
update_route_body.hostname, update_route_body.path
);

Ok(())
}
Expand Down
Loading