make it work inside and outside docker

This commit is contained in:
Bryan Stitt 2022-08-11 02:57:01 +00:00
parent f2fcf8f059
commit 6766f53422
4 changed files with 18 additions and 5 deletions

@ -92,6 +92,7 @@
- [ ] active requests on /status is always 0 even when i'm running requests through
- [ ] redis cell is giving errors under high load. maybe replace with https://redis.com/redis-best-practices/basic-rate-limiting/
- [ ] cli tool for resetting api keys
- [ ] cli tool for checking config
- [ ] nice output when cargo doc is run
- [ ] if we request an old block, more servers can handle it than we currently use.
- [ ] instead of the one list of just heads, store our intermediate mappings (rpcs_by_hash, rpcs_by_num, blocks_by_hash) in SyncedConnections. this shouldn't be too much slower than what we have now

@ -33,4 +33,4 @@ services:
volumes:
- ./config/example.toml:/config.toml
ports:
- 127.0.0.1:8544:8544
- 8544:8544

@ -560,7 +560,7 @@ impl Web3Connection {
// TODO: periodically check for listeners. if no one is subscribed, unsubscribe and wait for a subscription
}
warn!("subscription ended");
warn!(?self, "subscription ended");
}
}
}

@ -39,11 +39,23 @@ pub async fn serve(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()
let addr = SocketAddr::from(([0, 0, 0, 0], port));
info!("listening on port {}", port);
// TODO: into_make_service is enough if we always run behind a proxy. make into_make_service_with_connect_info optional?
/*
It sequentially looks for an IP in:
- x-forwarded-for header (de-facto standard)
- x-real-ip header
- forwarded header (new standard)
- axum::extract::ConnectInfo (if not behind proxy)
So we probably won't need into_make_service_with_connect_info, but it shouldn't hurt
*/
let service = app.into_make_service_with_connect_info::<SocketAddr>();
// let service = app.into_make_service();
axum::Server::bind(&addr)
// TODO: option to use with_connect_info. we want it in dev, but not when running behind a proxy, but not
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.with_graceful_shutdown(signal_shutdown())
// .serve(app.into_make_service())
.serve(service)
.with_graceful_shutdown(async { signal_shutdown().await })
.await
.map_err(Into::into)
}