summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/lib.rs
blob: f321d3fa6763b0dce84fbf5b5258bb22337b2212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

use anyhow::Result;
use log::{info, error};
use rouille::{Request, Response, router};

pub fn run_server() -> Result<()> {

    // TODO: log access requests
    // TODO: some static files? https://github.com/tomaka/rouille/blob/master/examples/static-files.rs

    let log_ok = |req: &Request, resp: &Response, elap: std::time::Duration| {
        info!("{} {} ({:?})", req.method(), req.raw_url(), elap);
    };
    let log_err = |req: &Request, elap: std::time::Duration| {
        error!("HTTP handler panicked: {} {} ({:?})", req.method(), req.raw_url(), elap);
    };
    rouille::start_server("localhost:3030", move |request| {
        rouille::log_custom(request, log_ok, log_err, || {
            router!(request,
                (GET) ["/"] => {
                    Response::text("Not much to see here yet!")
                },
                (GET) ["/xrpc/some.method"] => {
                    Response::text("didn't get a thing")
                    // TODO: reply with query params as a JSON body
                },
                (POST) ["/xrpc/other.method"] => {
                    Response::text("didn't get other thing")
                    // TODO: parse and echo back JSON body
                },
                _ => rouille::Response::empty_404()
            )
        })
    });
}