generated from ElnuDev/rust-project
tatoeba: add port configuration
This commit is contained in:
parent
aa56d3ce9f
commit
71ff7a6cdc
3 changed files with 138 additions and 1 deletions
|
@ -11,3 +11,4 @@ actix-web = "4.3.1"
|
|||
derive_more = "0.99.17"
|
||||
mime = "0.3.17"
|
||||
reqwest = "0.11.18"
|
||||
clap = { version = "4.3.21", features = ["derive"] }
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
use utils::{error::{Error, Result}, is_human};
|
||||
|
||||
use actix_web::{get, http::header, App, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||
use clap::Parser;
|
||||
|
||||
pub const TATOEBA_API: &str = "https://tatoeba.org/en/api_v0/search";
|
||||
|
||||
/// A proxy of the Tatoeba API with no CORS restrictions.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// The port at which to run.
|
||||
#[arg(short, long, default_value_t=3001)]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn root(request: HttpRequest) -> Result<impl Responder> {
|
||||
let target = format!("{TATOEBA_API}?{}", request.query_string());
|
||||
|
@ -19,7 +29,7 @@ async fn root(request: HttpRequest) -> Result<impl Responder> {
|
|||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(root))
|
||||
.bind(("127.0.0.1", 3001))?
|
||||
.bind(("127.0.0.1", Args::parse().port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue