Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o committed Sep 2, 2022
1 parent 458e4b0 commit 19ed5ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
21 changes: 9 additions & 12 deletions apollo-router/src/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ListenersAndRouters {
pub(crate) fn make_axum_router<RF>(
service_factory: RF,
configuration: &Configuration,
extra_endpoints: MultiMap<ListenAddr, Endpoint>,
extra_endpoints: MultiMap<Listener, Endpoint>,
) -> Result<ListenersAndRouters, ApolloRouterError>
where
RF: SupergraphServiceFactory,
Expand Down Expand Up @@ -175,9 +175,9 @@ where

let mut addrs_and_endpoints: MultiMap<ListenAddr, axum::Router> = Default::default();

addrs_and_endpoints.extend(web_endpoints.into_iter().map(|(listen_addr, endpoints)| {
addrs_and_endpoints.extend(extra_endpoints.into_iter().map(|(listen_addr, endpoints)| {
(
listen_addr,
listen_addr.into(),
endpoints
.into_iter()
.map(|e| e.into_router())
Expand Down Expand Up @@ -217,29 +217,26 @@ impl HttpServerFactory for AxumHttpServerFactory {
service_factory: RF,
configuration: Arc<Configuration>,
main_listener: Option<Listener>,
extra_endpoints: MultiMap<ListenAddr, Endpoint>,
extra_endpoints: MultiMap<Listener, Endpoint>,
) -> Self::Future
where
RF: SupergraphServiceFactory,
{
Box::pin(async move {
let all_routers = make_axum_router(service_factory, &configuration, web_endpoints)?;
let all_routers = make_axum_router(service_factory, &configuration, extra_endpoints)?;
let mut listeners_and_routers = Vec::with_capacity(all_routers.count());

// TODO [igni]: It may seem odd but I believe configuring the router
// To listen to port 0 would lead it to change ports on every restart Oo

// reuse previous listen addrs
for listener in all_routers.all.into_iter() {
if let Some((_, router)) = axum_router
.iter()
.find(|(l, _)| l == &listener.local_addr().unwrap())
{
listeners_and_routers.push((listener, router.clone()));
for listener in all_routers.extra.into_iter() {
if let Some((_, router)) = extra_endpoints.iter().find(|(l, _)| l == &&listener.0) {
listeners_and_routers.push((listener.0, router.clone()));
}
}
// populate the new listen addrs
for (listen_addr, router) in axum_router {
for ListenAddrAndRouter(listen_addr, router) in all_routers.extra {
// if we received a TCP listener, reuse it, otherwise create a new one
#[cfg_attr(not(unix), allow(unused_mut))]
let listener = match listen_addr {
Expand Down
7 changes: 3 additions & 4 deletions apollo-router/src/http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use itertools::Itertools;
use multimap::MultiMap;

use super::router::ApolloRouterError;
use crate::axum_http_server_factory::ListenersAndRouters;
use crate::configuration::Configuration;
use crate::configuration::ListenAddr;
use crate::router_factory::Endpoint;
Expand All @@ -25,8 +24,8 @@ pub(crate) trait HttpServerFactory {
&self,
service_factory: RF,
configuration: Arc<Configuration>,
web_endpoints: ListenersAndRouters,
web_endpoints: MultiMap<ListenAddr, Endpoint>,
main_listener: Option<Listener>,
extra_endpoints: MultiMap<Listener, Endpoint>,
) -> Self::Future
where
RF: SupergraphServiceFactory;
Expand Down Expand Up @@ -94,7 +93,7 @@ impl HttpServerHandle {
factory: &SF,
router: RF,
configuration: Arc<Configuration>,
web_endpoints: ListenersAndRouters,
web_endpoints: MultiMap<ListenAddr, Endpoint>,
) -> Result<Self, ApolloRouterError>
where
SF: HttpServerFactory,
Expand Down

0 comments on commit 19ed5ea

Please sign in to comment.