Skip to content

Commit a3561f5

Browse files
Replaces local, fastly backend config with dynamic backends.
Only required config is origin_url. Origin backend is deprecated.
1 parent c79068c commit a3561f5

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

crates/common/src/publisher.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use error_stack::{Report, ResultExt};
22
use fastly::http::{header, StatusCode};
33
use fastly::{Body, Request, Response};
4+
use url::Url;
45

6+
use crate::backend::ensure_origin_backend;
57
use crate::http_util::serve_static_with_etag;
68

79
use crate::constants::{
@@ -359,17 +361,28 @@ pub fn handle_publisher_request(
359361
has_synthetic_cookie
360362
);
361363

362-
// Extract host from the origin_url using the Publisher's origin_host method
363-
let origin_host = settings.publisher.origin_host();
364+
let parsed_url = Url::parse(&settings.publisher.origin_url)
365+
.change_context(TrustedServerError::Proxy {
366+
message: format!("Invalid origin_url: {}", settings.publisher.origin_url),
367+
})?;
368+
369+
let scheme = parsed_url.scheme();
370+
let origin_host = parsed_url.host_str().ok_or_else(|| {
371+
Report::new(TrustedServerError::Proxy {
372+
message: "Missing host in origin_url".to_string(),
373+
})
374+
})?;
375+
let port = parsed_url.port();
376+
377+
let backend_name = ensure_origin_backend(scheme, origin_host, port)?;
364378

365-
log::info!("Setting host header to: {}", origin_host);
366-
req.set_header("host", &origin_host);
379+
log::info!("Proxying to dynamic backend: {} (from {})", backend_name, settings.publisher.origin_url);
380+
req.set_header("host", origin_host);
367381

368-
// Send the request to the origin backend
369382
let mut response = req
370-
.send(&settings.publisher.origin_backend)
383+
.send(&backend_name)
371384
.change_context(TrustedServerError::Proxy {
372-
message: "Failed to proxy request".to_string(),
385+
message: "Failed to proxy request to origin".to_string(),
373386
})?;
374387

375388
// Log all response headers for debugging

crates/common/src/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct AdServer {
2121
pub struct Publisher {
2222
pub domain: String,
2323
pub cookie_domain: String,
24+
#[deprecated(note = "Use origin_url instead - dynamic backends are created automatically")]
2425
pub origin_backend: String,
2526
pub origin_url: String,
2627
/// Secret used to encrypt/decrypt proxied URLs in `/first-party/proxy`.

fastly.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ build = """
6767
[local_server.backends.googleads_doubleclick_backend]
6868
url = "https://securepubads.g.doubleclick.net"
6969

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

trusted-server.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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+
# DEPRECATED origin backend is now dynamically created
89
origin_backend = "publisher_origin"
910
origin_url = "https://origin.test-publisher.com"
1011
proxy_secret = "change-me-proxy-secret"

0 commit comments

Comments
 (0)