server: version bump and cleanup.

This commit is contained in:
2022-11-13 15:42:23 -08:00
parent 1477980395
commit 4f9bc9ef9d
2 changed files with 16 additions and 14 deletions

View File

@@ -3,17 +3,16 @@ extern crate rocket;
use std::{error::Error, io::Cursor, str::FromStr};
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
use rocket::{
http::{ContentType, Header},
request::Request,
response::{content::Plain, Debug, Responder},
response::{Debug, Responder},
serde::json::Json,
Response, State,
};
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
@@ -75,14 +74,17 @@ async fn original_part(
}
#[get("/original/<id>")]
async fn original(nm: &State<Notmuch>, id: &str) -> Result<Plain<Vec<u8>>, Debug<NotmuchError>> {
async fn original(
nm: &State<Notmuch>,
id: &str,
) -> Result<(ContentType, Vec<u8>), Debug<NotmuchError>> {
let mid = if id.starts_with("id:") {
id.to_string()
} else {
format!("id:{}", id)
};
let res = nm.show_original(&mid)?;
Ok(Plain(res))
Ok((ContentType::Plain, res))
}
#[rocket::main]
@@ -100,11 +102,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
.to_cors()?;
rocket::build()
let _ = rocket::build()
.mount("/", routes![original_part, original, hello, search, show])
.attach(cors)
//.manage(Notmuch::default())
.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
.manage(Notmuch::default())
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
.launch()
.await?;