tatoeba: add port configuration

This commit is contained in:
Elnu 2023-08-12 12:41:42 -07:00
parent aa56d3ce9f
commit 71ff7a6cdc
3 changed files with 138 additions and 1 deletions

View file

@ -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"] }

View file

@ -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
}