neveko/src/main.rs

71 lines
1.9 KiB
Rust
Raw Normal View History

2023-04-30 15:55:41 +00:00
#[macro_use]
extern crate rocket;
2023-05-09 21:28:07 +00:00
use rocket::{
http::Status,
response::status::Custom,
serde::json::Json,
};
2023-04-30 15:55:41 +00:00
use nevmes::*;
2023-05-02 05:11:15 +00:00
use nevmes_core::*;
2023-04-30 15:55:41 +00:00
2023-05-08 08:02:38 +00:00
#[catch(402)]
fn payment_required() -> Custom<Json<reqres::ErrorResponse>> {
2023-05-09 21:28:07 +00:00
Custom(
Status::PaymentRequired,
Json(reqres::ErrorResponse {
error: String::from("Payment required"),
}),
)
2023-05-08 08:02:38 +00:00
}
#[catch(404)]
fn not_found() -> Custom<Json<reqres::ErrorResponse>> {
2023-05-09 21:28:07 +00:00
Custom(
Status::NotFound,
Json(reqres::ErrorResponse {
error: String::from("Resource does not exist"),
}),
)
2023-05-08 08:02:38 +00:00
}
#[catch(500)]
fn internal_error() -> Custom<Json<reqres::ErrorResponse>> {
2023-05-09 21:28:07 +00:00
Custom(
Status::InternalServerError,
Json(reqres::ErrorResponse {
error: String::from("Internal server error"),
}),
)
2023-05-08 08:02:38 +00:00
}
// The only changes below here should be mounting new controller methods
2023-04-30 15:55:41 +00:00
#[launch]
async fn rocket() -> _ {
let config = rocket::Config {
ident: rocket::config::Ident::none(),
ip_header: None,
port: utils::get_app_port(),
..rocket::Config::debug_default()
};
env_logger::init();
utils::start_up().await;
rocket::custom(&config)
2023-05-08 08:02:38 +00:00
.register("/", catchers![internal_error, not_found, payment_required])
.mount("/multisig/info", routes![controller::get_multisig_info])
2023-04-30 15:55:41 +00:00
.mount("/invoice", routes![controller::gen_invoice])
.mount("/message/rx", routes![controller::rx_message])
2023-06-03 05:13:56 +00:00
.mount(
"/message/rx/multisig",
routes![controller::rx_multisig_message],
)
2023-04-30 15:55:41 +00:00
.mount("/prove", routes![controller::gen_jwp])
.mount("/share", routes![controller::share_contact_info])
.mount("/i2p", routes![controller::get_i2p_status])
.mount("/xmr/rpc", routes![controller::get_version])
2023-06-03 05:13:56 +00:00
.mount(
"/market",
routes![controller::create_order, controller::get_products],
)
2023-04-30 15:55:41 +00:00
}