Skip to content

Commit

Permalink
Merge pull request #5 from hjr3/qm-add-listener-config-support
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinMoss authored Jul 1, 2023
2 parents eb486a8 + 92bb919 commit 9b6e52f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 0 additions & 2 deletions examples/example_config

This file was deleted.

2 changes: 2 additions & 0 deletions soldr.example.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
database_url = "sqlite:soldr.db?mode=rwc"
management_listener = "0.0.0.0:3444"
ingest_listener = "0.0.0.0:3001"
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use axum::{routing::post, Router};
use hyper::HeaderMap;
use serde::Deserialize;
use sqlx::sqlite::SqlitePool;
use std::net::SocketAddr;
use tracing::Level;

use crate::db::{ensure_schema, insert_request, mark_complete, mark_error};
Expand Down Expand Up @@ -45,11 +44,9 @@ impl Default for Config {
}
}

pub async fn app(config: Config) -> Result<(Router, Router, SqlitePool, SocketAddr, SocketAddr)> {
pub async fn app(config: &Config) -> Result<(Router, Router, SqlitePool)> {
let pool = SqlitePool::connect(&config.database_url).await?;
let pool2 = pool.clone();
let mgmt_listener = config.management_listener.parse()?;
let ingest_listener = config.ingest_listener.parse()?;

ensure_schema(&pool).await?;

Expand All @@ -62,7 +59,7 @@ pub async fn app(config: Config) -> Result<(Router, Router, SqlitePool, SocketAd
.layer(Extension(pool))
.with_state(client);

Ok((router, mgmt_router, pool2, mgmt_listener, ingest_listener))
Ok((router, mgmt_router, pool2))
}

async fn handler(
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ async fn main() -> Result<()> {
None => soldr::Config::default(),
};

let (ingest, mgmt, pool, mgmt_listener, ingest_listner) = soldr::app(config).await?;
let (ingest, mgmt, pool) = soldr::app(&config).await?;

let mgmt_listener = config.management_listener.parse()?;
let ingest_listener = config.ingest_listener.parse()?;

tokio::spawn(async move {
tracing::info!("management API listening on {}", mgmt_listener);
Expand All @@ -52,8 +55,8 @@ async fn main() -> Result<()> {
}
});

tracing::info!("ingest listening on {}", ingest_listner);
axum::Server::bind(&ingest_listner)
tracing::info!("ingest listening on {}", ingest_listener);
axum::Server::bind(&ingest_listener)
.serve(ingest.into_make_service())
.await?;

Expand Down
4 changes: 2 additions & 2 deletions tests/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn ingest_save_and_proxy() {
.unwrap();
});

let (ingest, mgmt, _, _, _) = app(common::config()).await.unwrap();
let (ingest, mgmt, _) = app(&common::config()).await.unwrap();

// create an origin mapping
let domain = "example.wh.soldr.dev";
Expand Down Expand Up @@ -153,7 +153,7 @@ async fn ingest_proxy_error() {
.unwrap();
});

let (ingest, mgmt, _, _, _) = app(common::config()).await.unwrap();
let (ingest, mgmt, _) = app(&common::config()).await.unwrap();

// create an origin mapping
let domain = "example.wh.soldr.dev";
Expand Down
4 changes: 2 additions & 2 deletions tests/mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use soldr::{app, db};

#[tokio::test]
async fn mgmt_list_requests() {
let (_, mgmt, _, _, _) = app(common::config()).await.unwrap();
let (_, mgmt, _) = app(&common::config()).await.unwrap();

let response = mgmt
.oneshot(
Expand All @@ -31,7 +31,7 @@ async fn mgmt_list_requests() {

#[tokio::test]
async fn mgmt_create_origin() {
let (_, mgmt, _, _, _) = app(common::config()).await.unwrap();
let (_, mgmt, _) = app(&common::config()).await.unwrap();

let create_origin = CreateOrigin {
domain: "example.wh.soldr.dev".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion tests/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn queue_retry_request() {
.unwrap();
});

let (ingest, mgmt, pool, _, _) = app(common::config()).await.unwrap();
let (ingest, mgmt, pool) = app(&common::config()).await.unwrap();

// create an origin mapping
let domain = "example.wh.soldr.dev";
Expand Down

0 comments on commit 9b6e52f

Please sign in to comment.