mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Put Http server into GLOBALS
This commit is contained in:
parent
445cc89530
commit
259883d2b7
@ -1,5 +1,6 @@
|
||||
use crate::config::Config;
|
||||
use crate::store::Store;
|
||||
use hyper::server::conn::Http;
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::OnceLock;
|
||||
use tokio::sync::RwLock;
|
||||
@ -7,13 +8,19 @@ use tokio::sync::RwLock;
|
||||
pub struct Globals {
|
||||
pub config: RwLock<Config>,
|
||||
pub store: OnceLock<Store>,
|
||||
pub http_server: Http,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref GLOBALS: Globals = {
|
||||
let mut http_server = hyper::server::conn::Http::new();
|
||||
http_server.http1_only(true);
|
||||
http_server.http1_keep_alive(true);
|
||||
|
||||
Globals {
|
||||
config: RwLock::new(Config::default()),
|
||||
store: OnceLock::new(),
|
||||
http_server,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -81,21 +81,17 @@ async fn main() -> Result<(), Error> {
|
||||
// Store config into GLOBALS
|
||||
*GLOBALS.config.write().await = config;
|
||||
|
||||
let mut http_server = hyper::server::conn::Http::new();
|
||||
http_server.http1_only(true);
|
||||
http_server.http1_keep_alive(true);
|
||||
|
||||
// Accepts network connections and spawn a task to serve each one
|
||||
loop {
|
||||
let (tcp_stream, peer_addr) = listener.accept().await?;
|
||||
|
||||
let acceptor = tls_acceptor.clone();
|
||||
let http_server_clone = http_server.clone();
|
||||
tokio::spawn(async move {
|
||||
match acceptor.accept(tcp_stream).await {
|
||||
Err(e) => log::error!("{}", e),
|
||||
Ok(tls_stream) => {
|
||||
let connection = http_server_clone
|
||||
let connection = GLOBALS
|
||||
.http_server
|
||||
.serve_connection(tls_stream, hyper::service::service_fn(handle_request));
|
||||
tokio::spawn(async move {
|
||||
// If our service exits with an error, log the error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user