Browse Source

Initial commit

main
Victor Roest 7 months ago
commit
ed3f759403
Signed by: 0x76 GPG Key ID: A3923C699D1A3BDA
  1. 1
      .gitignore
  2. 1299
      Cargo.lock
  3. 14
      Cargo.toml
  4. 33
      src/main.rs

1
.gitignore

@ -0,0 +1 @@
/target

1299
Cargo.lock

File diff suppressed because it is too large

14
Cargo.toml

@ -0,0 +1,14 @@
[package]
name = "cors-no-more"
version = "0.1.0"
authors = ["Victor Roest <victor@xirion.net>"]
edition = "2018"
[dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
warp = "0.3"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
http = "0.2"
[profile.release]
lto = true

33
src/main.rs

@ -0,0 +1,33 @@
use http::Method;
use warp::{path::FullPath, Filter, Rejection};
#[tokio::main]
async fn main() {
let cors = warp::cors().allow_any_origin();
let routes = warp::path::full()
.and(warp::method())
.and(warp::query::raw())
.and_then(proxy)
.with(cors);
warp::serve(routes).run(([0, 0, 0, 0], 8282)).await;
}
async fn proxy(path: FullPath, method: Method, query: String) -> Result<String, Rejection> {
let p: String = format!("{}?{}", path.as_str().strip_prefix("/").unwrap(), query);
dbg!(&p);
let client = reqwest::Client::new();
let response = client
.request(method, p)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
Ok(response)
}
Loading…
Cancel
Save