Browse Source

Add simple static server binary.

wip
Titouan Rigoudy 4 years ago
parent
commit
c46876a2b4
2 changed files with 20 additions and 0 deletions
  1. +19
    -0
      server/examples/static.rs
  2. +1
    -0
      server/src/server.rs

+ 19
- 0
server/examples/static.rs View File

@ -0,0 +1,19 @@
//! A simple server that serves static responses.
// TODO: Serve responses with UserStatusHandler, initialize state from some
// TOML config file.
use anyhow::Context;
use solstice_server::{LogHandlerFactory, ServerBuilder};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let (server, _handle) = ServerBuilder::new(LogHandlerFactory)
.bind()
.await
.context("binding server")?;
server.serve().await
}

+ 1
- 0
server/src/server.rs View File

@ -189,6 +189,7 @@ where
pub async fn bind(self) -> anyhow::Result<(Server<F>, ServerHandle)> { pub async fn bind(self) -> anyhow::Result<(Server<F>, ServerHandle)> {
let listener = TcpListener::bind("localhost:0").await.context("binding")?; let listener = TcpListener::bind("localhost:0").await.context("binding")?;
let address = listener.local_addr().context("getting local address")?; let address = listener.local_addr().context("getting local address")?;
info!("Server listening on {}", address);
let (shutdown_tx, shutdown_rx) = oneshot::channel(); let (shutdown_tx, shutdown_rx) = oneshot::channel();
let (handler_shutdown_tx, handler_shutdown_rx) = watch::channel(()); let (handler_shutdown_tx, handler_shutdown_rx) = watch::channel(());


Loading…
Cancel
Save