Skip to content

Commit 74380bd

Browse files
Replaces local, fastly backend config with dynamic backends. (#49)
* Replaces local, fastly backend config with dynamic backends. Only required config is origin_url. Origin backend is deprecated. * Removes prebid config for dynamic prebid backend * completely removes origin_backend setting * update CHANGELOG.md
1 parent c79068c commit 74380bd

File tree

8 files changed

+59
-27
lines changed

8 files changed

+59
-27
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [1.2.0] - 2025-10-14
10+
11+
### Changed
12+
- Publisher origin backend now uses `publisher.origin_url` to dynamically create backends, deprecated `publisher.origin_backend` field
13+
- Prebid backend now uses `prebid.server_url` to dynamically create backends, deprecated `prebid.prebid_backend` field
14+
- Removed static backend definitions from `fastly.toml` for publisher and prebid
15+
16+
### Added
17+
- Added `.rust-analyzer.json` for improved development environment support with Neovim/rust-analyzer
18+
919
## [1.1.0] - 2025-10-05
1020

1121
### Added
@@ -82,7 +92,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8292

8393
- Initial implementation of Trusted Server
8494

85-
[Unreleased]:https://github.com/IABTechLab/trusted-server/compare/v1.0.6...HEAD
95+
[Unreleased]:https://github.com/IABTechLab/trusted-server/compare/v1.2.0...HEAD
96+
[1.2.0]:https://github.com/IABTechLab/trusted-server/compare/v1.1.0...v1.2.0
97+
[1.1.0]:https://github.com/IABTechLab/trusted-server/compare/v1.0.6...v1.1.0
8698
[1.0.6]:https://github.com/IABTechLab/trusted-server/compare/v1.0.5...v1.0.6
8799
[1.0.5]:https://github.com/IABTechLab/trusted-server/compare/v1.0.4...v1.0.5
88100
[1.0.4]:https://github.com/IABTechLab/trusted-server/compare/v1.0.3...v1.0.4

crates/common/src/backend.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::time::Duration;
22

3-
use error_stack::Report;
3+
use error_stack::{Report, ResultExt};
44
use fastly::backend::Backend;
5+
use url::Url;
56

67
use crate::error::TrustedServerError;
78

@@ -66,6 +67,21 @@ pub fn ensure_origin_backend(
6667
}
6768
}
6869
}
70+
pub fn ensure_backend_from_url(origin_url: &str) -> Result<String, Report<TrustedServerError>> {
71+
let parsed_url = Url::parse(origin_url).change_context(TrustedServerError::Proxy {
72+
message: format!("Invalid origin_url: {}", origin_url),
73+
})?;
74+
75+
let scheme = parsed_url.scheme();
76+
let host = parsed_url.host_str().ok_or_else(|| {
77+
Report::new(TrustedServerError::Proxy {
78+
message: "Missing host in origin_url".to_string(),
79+
})
80+
})?;
81+
let port = parsed_url.port();
82+
83+
ensure_origin_backend(scheme, host, port)
84+
}
6985

7086
#[cfg(test)]
7187
mod tests {

crates/common/src/prebid.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use fastly::http::{header, Method, StatusCode};
88
use fastly::{Error, Request, Response};
99
use serde_json::json;
1010

11+
use crate::backend::ensure_backend_from_url;
1112
use crate::constants::{
1213
HEADER_SYNTHETIC_FRESH, HEADER_SYNTHETIC_TRUSTED_SERVER, HEADER_X_COMPRESS_HINT,
1314
HEADER_X_CONSENT_ADVERTISING, HEADER_X_FORWARDED_FOR,
@@ -194,10 +195,17 @@ impl PrebidRequest {
194195
id
195196
);
196197

197-
req.set_body_json(&prebid_body)?;
198+
// TrustedServerError doesn't implement std::error::Error
199+
match ensure_backend_from_url(&settings.prebid.server_url) {
200+
Ok(backend_name) => {
201+
req.set_body_json(&prebid_body)?;
198202

199-
let resp = req.send("prebid_backend")?;
200-
Ok(resp)
203+
let resp = req.send(backend_name)?;
204+
Ok(resp)
205+
}
206+
207+
Err(e) => fastly::error::bail!("Could not get prebid backend: {}", e),
208+
}
201209
}
202210
}
203211

crates/common/src/prebid_proxy.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use fastly::http::{header, Method, StatusCode};
99
use fastly::{Request, Response};
1010
use serde_json::{json, Value};
1111

12+
use crate::backend::ensure_backend_from_url;
1213
use crate::constants::{HEADER_SYNTHETIC_FRESH, HEADER_SYNTHETIC_TRUSTED_SERVER};
1314
use crate::error::TrustedServerError;
1415
use crate::gdpr::get_consent_from_request;
@@ -78,10 +79,12 @@ pub async fn handle_prebid_auction(
7879

7980
log::info!("Sending request to Prebid Server");
8081

82+
let backend_name = ensure_backend_from_url(&settings.prebid.server_url)?;
83+
8184
// 5. Send to PBS and get response
8285
let mut pbs_response =
8386
pbs_req
84-
.send("prebid_backend")
87+
.send(backend_name)
8588
.change_context(TrustedServerError::Prebid {
8689
message: "Failed to send request to Prebid Server".to_string(),
8790
})?;
@@ -175,9 +178,12 @@ pub async fn handle_prebid_cookie_sync(
175178
})?;
176179

177180
// 4. Get response and transform sync URLs
181+
182+
let backend_name = ensure_backend_from_url(&settings.prebid.server_url)?;
183+
178184
let mut pbs_response =
179185
pbs_req
180-
.send("prebid_backend")
186+
.send(backend_name)
181187
.change_context(TrustedServerError::Prebid {
182188
message: "Failed to send cookie sync request".to_string(),
183189
})?;

crates/common/src/publisher.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use error_stack::{Report, ResultExt};
22
use fastly::http::{header, StatusCode};
33
use fastly::{Body, Request, Response};
44

5+
use crate::backend::ensure_backend_from_url;
56
use crate::http_util::serve_static_with_etag;
67

78
use crate::constants::{
@@ -359,17 +360,20 @@ pub fn handle_publisher_request(
359360
has_synthetic_cookie
360361
);
361362

362-
// Extract host from the origin_url using the Publisher's origin_host method
363+
let backend_name = ensure_backend_from_url(&settings.publisher.origin_url)?;
363364
let origin_host = settings.publisher.origin_host();
364365

365-
log::info!("Setting host header to: {}", origin_host);
366+
log::info!(
367+
"Proxying to dynamic backend: {} (from {})",
368+
backend_name,
369+
settings.publisher.origin_url
370+
);
366371
req.set_header("host", &origin_host);
367372

368-
// Send the request to the origin backend
369373
let mut response = req
370-
.send(&settings.publisher.origin_backend)
374+
.send(&backend_name)
371375
.change_context(TrustedServerError::Proxy {
372-
message: "Failed to proxy request".to_string(),
376+
message: "Failed to proxy request to origin".to_string(),
373377
})?;
374378

375379
// Log all response headers for debugging

crates/common/src/settings.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub struct AdServer {
2121
pub struct Publisher {
2222
pub domain: String,
2323
pub cookie_domain: String,
24-
pub origin_backend: String,
2524
pub origin_url: String,
2625
/// Secret used to encrypt/decrypt proxied URLs in `/first-party/proxy`.
2726
/// Keep this secret stable to allow existing links to decode.
@@ -38,7 +37,6 @@ impl Publisher {
3837
/// let publisher = Publisher {
3938
/// domain: "example.com".to_string(),
4039
/// cookie_domain: ".example.com".to_string(),
41-
/// origin_backend: "edgepubs_main_be".to_string(),
4240
/// origin_url: "https://origin.example.com:8080".to_string(),
4341
/// proxy_secret: "proxy-secret".to_string(),
4442
/// };
@@ -530,7 +528,6 @@ mod tests {
530528
let publisher = Publisher {
531529
domain: "example.com".to_string(),
532530
cookie_domain: ".example.com".to_string(),
533-
origin_backend: "publisher_origin".to_string(),
534531
origin_url: "https://origin.example.com:8080".to_string(),
535532
proxy_secret: "test-secret".to_string(),
536533
};
@@ -540,7 +537,6 @@ mod tests {
540537
let publisher = Publisher {
541538
domain: "example.com".to_string(),
542539
cookie_domain: ".example.com".to_string(),
543-
origin_backend: "publisher_origin".to_string(),
544540
origin_url: "https://origin.example.com".to_string(),
545541
proxy_secret: "test-secret".to_string(),
546542
};
@@ -550,7 +546,6 @@ mod tests {
550546
let publisher = Publisher {
551547
domain: "example.com".to_string(),
552548
cookie_domain: ".example.com".to_string(),
553-
origin_backend: "publisher_origin".to_string(),
554549
origin_url: "http://localhost:9090".to_string(),
555550
proxy_secret: "test-secret".to_string(),
556551
};
@@ -560,7 +555,6 @@ mod tests {
560555
let publisher = Publisher {
561556
domain: "example.com".to_string(),
562557
cookie_domain: ".example.com".to_string(),
563-
origin_backend: "publisher_origin".to_string(),
564558
origin_url: "localhost:9090".to_string(),
565559
proxy_secret: "test-secret".to_string(),
566560
};
@@ -570,7 +564,6 @@ mod tests {
570564
let publisher = Publisher {
571565
domain: "example.com".to_string(),
572566
cookie_domain: ".example.com".to_string(),
573-
origin_backend: "publisher_origin".to_string(),
574567
origin_url: "http://192.168.1.1:8080".to_string(),
575568
proxy_secret: "test-secret".to_string(),
576569
};
@@ -580,7 +573,6 @@ mod tests {
580573
let publisher = Publisher {
581574
domain: "example.com".to_string(),
582575
cookie_domain: ".example.com".to_string(),
583-
origin_backend: "publisher_origin".to_string(),
584576
origin_url: "http://[::1]:8080".to_string(),
585577
proxy_secret: "test-secret".to_string(),
586578
};

fastly.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ build = """
4444

4545
[local_server.backends.equativ_ad_api_2]
4646
url = "https://adapi-srv-eu.smartadserver.com"
47-
[local_server.backends.prebid_backend]
48-
url = "http://68.183.113.79:8000"
47+
4948
[local_server.backends.gam_backend]
5049
url = "https://securepubads.g.doubleclick.net"
5150
[local_server.backends.wordpress_backend]
@@ -67,10 +66,6 @@ build = """
6766
[local_server.backends.googleads_doubleclick_backend]
6867
url = "https://securepubads.g.doubleclick.net"
6968

70-
[local_server.backends.publisher_origin]
71-
url = "http://localhost:9090"
72-
override_host = "localhost:9090"
73-
7469
# Backend for proxying ad creatives and tracking pixels
7570
[local_server.backends.ad_cdn_backend]
7671
url = "https://cdn.adsrvr.org" # Default, will be overridden dynamically

trusted-server.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ sync_url = "https://adapi-srv-eu.smartadserver.com/ac?pgid=2040327&fmtid=137675&
55
[publisher]
66
domain = "test-publisher.com"
77
cookie_domain = ".test-publisher.com"
8-
origin_backend = "publisher_origin"
98
origin_url = "https://origin.test-publisher.com"
109
proxy_secret = "change-me-proxy-secret"
1110

0 commit comments

Comments
 (0)