Skip to content

How to run servers on multiple ports simultaneously? #367

Answered by jbr
joshtriplett asked this question in Q&A
Discussion options

You must be logged in to vote

This is definitely something trillium supports doing, and in fact as a relatively-unopinionated toolkit, there are a few different ways of doing it. I'll offer the most straightforward way to meet the constraints, but depending on how much you've simplified, it may not be the ideal solution.

use trillium::Conn;
use trillium_router::router;
use trillium_smol::{async_global_executor::block_on, config};

async fn a(conn: Conn) -> Conn {
    conn.ok("a")
}

async fn b(conn: Conn) -> Conn {
    conn.ok("b")
}

async fn c(conn: Conn) -> Conn {
    conn.ok("c")
}

fn main() {
    block_on(async {
        let leader = config()
            .with_port(8080)
            .with_host("0.0.0.0")

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@joshtriplett
Comment options

@jbr
Comment options

jbr Sep 13, 2023
Maintainer

Answer selected by joshtriplett
@joshtriplett
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #366 on September 13, 2023 03:01.