server: version bump and cleanup.
This commit is contained in:
parent
1477980395
commit
4f9bc9ef9d
@ -6,15 +6,15 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { version = "0.5.0-rc.1", features = [ "json" ] }
|
rocket = { version = "0.5.0-rc.2", features = [ "json" ] }
|
||||||
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", branch = "master" }
|
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", branch = "master" }
|
||||||
notmuch = { path = "../notmuch" }
|
notmuch = { path = "../notmuch" }
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.87"
|
||||||
thiserror = "1.0.26"
|
thiserror = "1.0.37"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
log = "0.4.14"
|
log = "0.4.17"
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
version = "0.4.10"
|
version = "0.4.11"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["json"]
|
features = ["json"]
|
||||||
|
|||||||
@ -3,17 +3,16 @@ extern crate rocket;
|
|||||||
|
|
||||||
use std::{error::Error, io::Cursor, str::FromStr};
|
use std::{error::Error, io::Cursor, str::FromStr};
|
||||||
|
|
||||||
|
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::{ContentType, Header},
|
http::{ContentType, Header},
|
||||||
request::Request,
|
request::Request,
|
||||||
response::{content::Plain, Debug, Responder},
|
response::{Debug, Responder},
|
||||||
serde::json::Json,
|
serde::json::Json,
|
||||||
Response, State,
|
Response, State,
|
||||||
};
|
};
|
||||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||||
|
|
||||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn hello() -> &'static str {
|
fn hello() -> &'static str {
|
||||||
"Hello, world!"
|
"Hello, world!"
|
||||||
@ -75,14 +74,17 @@ async fn original_part(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/original/<id>")]
|
#[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:") {
|
let mid = if id.starts_with("id:") {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("id:{}", id)
|
format!("id:{}", id)
|
||||||
};
|
};
|
||||||
let res = nm.show_original(&mid)?;
|
let res = nm.show_original(&mid)?;
|
||||||
Ok(Plain(res))
|
Ok((ContentType::Plain, res))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
@ -100,11 +102,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
.to_cors()?;
|
.to_cors()?;
|
||||||
|
|
||||||
rocket::build()
|
let _ = rocket::build()
|
||||||
.mount("/", routes![original_part, original, hello, search, show])
|
.mount("/", routes![original_part, original, hello, search, show])
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
//.manage(Notmuch::default())
|
.manage(Notmuch::default())
|
||||||
.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user