Skip to content

Commit

Permalink
Ensure config.json includes scheme in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Aug 28, 2024
1 parent 6f4eae4 commit 92f1b68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Finally, a config file using the above:
```yaml
service:
address: "127.0.0.1:3000"
download_endpoint: "127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "127.0.0.1:3000"
metrics_address: "127.0.0.1:3001"
download_endpoint: "http://127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "http://127.0.0.1:3000"

# for postgres backend
index_db: &db
Expand Down
14 changes: 13 additions & 1 deletion crates/freighter-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ pub struct ServiceConfig {
pub crate_size_limit: usize,
}

impl ServiceConfig {
pub fn sanitize(&mut self) {
if !self.api_endpoint.contains("://") {
self.api_endpoint = format!("https://{}", self.api_endpoint);
}
if !self.download_endpoint.contains("://") {
self.download_endpoint = format!("https://{}", self.download_endpoint);
}
}
}

pub struct ServiceState<I, S, A> {
pub config: ServiceConfig,
pub index: I,
Expand All @@ -55,7 +66,8 @@ pub struct ServiceState<I, S, A> {
}

impl<I, S, A> ServiceState<I, S, A> {
pub fn new(config: ServiceConfig, index: I, storage: S, auth: A) -> Self {
pub fn new(mut config: ServiceConfig, index: I, storage: S, auth: A) -> Self {
config.sanitize();
Self {
config,
index,
Expand Down
4 changes: 2 additions & 2 deletions crates/freighter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Finally, a config file using the above:
```yaml
service:
address: "127.0.0.1:3000"
download_endpoint: "127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "127.0.0.1:3000"
metrics_address: "127.0.0.1:3001"
download_endpoint: "http://127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "http://127.0.0.1:3000"

index_db: &db
dbname: "freighter"
Expand Down
4 changes: 2 additions & 2 deletions docker/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
service:
address: "127.0.0.1:3000"
download_endpoint: "127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "127.0.0.1:3000"
metrics_address: "127.0.0.1:3001"
download_endpoint: "http://127.0.0.1:3000/downloads/{crate}/{version}"
api_endpoint: "http://127.0.0.1:3000"
auth_required: true

index_db: &db
Expand Down

0 comments on commit 92f1b68

Please sign in to comment.