generated from ElnuDev/rust-project
images: add port configuration
This commit is contained in:
parent
71ff7a6cdc
commit
68028e700e
3 changed files with 13 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -894,6 +894,7 @@ name = "images"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"clap",
|
||||
"lazy_static",
|
||||
"mime",
|
||||
"rand",
|
||||
|
|
|
@ -14,3 +14,4 @@ scraper = "0.17.1"
|
|||
lazy_static = "1.4.0"
|
||||
rand = "0.8.5"
|
||||
serde_json = "1.0.104"
|
||||
clap = { version = "4.3.21", features = ["derive"] }
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
use utils::error::Result;
|
||||
|
||||
use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder};
|
||||
use clap::Parser;
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
pub const BING: &str = "https://www.bing.com/images/search";
|
||||
|
||||
/// An API for fetching images of a query, sourced from Microsoft Bing.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// The port at which to run.
|
||||
#[arg(short, long, default_value_t=3002)]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
async fn get_images(query: &str) -> reqwest::Result<Vec<String>> {
|
||||
use lazy_static::lazy_static;
|
||||
use scraper::{Html, Selector};
|
||||
|
@ -70,7 +80,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(route_query_random)
|
||||
.service(route_query_index)
|
||||
})
|
||||
.bind(("127.0.0.1", 3002))?
|
||||
.bind(("127.0.0.1", Args::parse().port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue