Skip to content

Commit

Permalink
fix: fix api url parsing, pegboard install (#1240)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Oct 24, 2024
1 parent 0194031 commit b420f2e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/api-helper/build/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ pub trait ApiAuth: Sized {
rate_limit_ctx: AuthRateLimitCtx<'_>,
) -> GlobalResult<Self>;

async fn rate_limit(config: &rivet_config::Config, rate_limit_ctx: AuthRateLimitCtx<'_>) -> GlobalResult<()>;
async fn rate_limit(
config: &rivet_config::Config,
rate_limit_ctx: AuthRateLimitCtx<'_>,
) -> GlobalResult<()>;
}

pub struct AuthRateLimitCtx<'a> {
Expand Down
20 changes: 17 additions & 3 deletions lib/api-helper/build/src/macro_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,32 @@ pub struct __RouterConfig {
#[doc(hidden)]
impl __RouterConfig {
pub fn new(config: &rivet_config::Config, uri: &hyper::Uri) -> GlobalResult<Self> {
// NOTE: We do not use `Url::join` because it normalizes paths
// This url doesn't actually represent the url of the request, it's just put here so that the
// URI can be parsed by url::Url::parse
let url = format!("{}{}", config.server()?.rivet.api.public_origin, uri);
let url = format!(
"{}{}",
config
.server()?
.rivet
.api
.public_origin
.to_string()
.trim_end_matches('/'),
uri,
);
let route = url::Url::parse(url.as_str())?;

Ok(__RouterConfig {
route: route.clone(),
path_segments: route
.path_segments()
.into_iter()
.flatten()
.map(ToString::to_string)
// Store it backwards for more efficient `pop`ing
.map(|ps| ps.rev().map(ToString::to_string).collect::<Vec<_>>())
.unwrap_or_default(),
.rev()
.collect::<Vec<_>>(),
prefix: None,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn install(config: &rivet_config::Config) -> GlobalResult<String> {
.to_string();

Ok(include_str!("../files/pegboard_install.sh")
.replace("__MANAGER_BINARY_URL__", &manager_binary_url)
.replace("__PEGBOARD_MANAGER_BINARY_URL__", &manager_binary_url)
.replace(
"__CONTAINER_RUNNER_BINARY_URL__",
&container_runner_binary_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ sysctl --system
mkdir -p /etc/pegboard
mkdir -p /etc/pegboard/bin

curl -Lf -o /usr/bin/pegboard "__BINARY_URL__"
curl -Lf -o /usr/bin/pegboard "__PEGBOARD_MANAGER_BINARY_URL__"
chmod +x /usr/bin/pegboard

curl -Lf -o /usr/bin/pegboard "__CONTAINER_RUNNER_BINARY_URL__"
chmod +x /usr/bin/pegboard/bin/container-runner
curl -Lf -o /etc/pegboard/bin/container-runner "__CONTAINER_RUNNER_BINARY_URL__"
chmod +x /etc/pegboard/bin/container-runner

curl -Lf -o /usr/bin/pegboard "__V8_ISOLATE_BINARY_URL__"
chmod +x /usr/bin/pegboard/bin/v8-isolate-runner
curl -Lf -o /etc/pegboard/bin/v8-isolate-runner "__V8_ISOLATE_BINARY_URL__"
chmod +x /etc/pegboard/bin/v8-isolate-runner

0 comments on commit b420f2e

Please sign in to comment.