chatgpt example proxy server
This commit is contained in:
commit
0b44c6afe2
4 files changed
+2345
No files matched your search
+39
@@ -0,0 +1,39 @@
|
||||
use actix_cors::Cors;
|
||||
use actix_web::{App, HttpResponse, HttpServer, Responder, get, http::header};
|
||||
use reqwest::Client;
|
||||
|
||||
#[get("/fetch-ics")]
|
||||
async fn fetch_ics() -> impl Responder {
|
||||
println!("pinged");
|
||||
let client = Client::new();
|
||||
let ics_url = "https://calendar.google.com/calendar/ical/i7p4ol56gi8sqe0dq7uc3m0o4c%40group.calendar.google.com/public/basic.ics";
|
||||
|
||||
match client.get(ics_url).send().await {
|
||||
Ok(response) => {
|
||||
if let Ok(body) = response.text().await {
|
||||
HttpResponse::Ok()
|
||||
.insert_header((header::CONTENT_TYPE, "text/calendar"))
|
||||
.body(body)
|
||||
} else {
|
||||
HttpResponse::InternalServerError().body("Failed to read response body")
|
||||
}
|
||||
}
|
||||
Err(_) => HttpResponse::BadGateway().body("Failed to fetch ICS file"),
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
let cors = Cors::default()
|
||||
.allow_any_origin()
|
||||
.allowed_methods(vec!["GET"])
|
||||
.allowed_headers(vec![header::CONTENT_TYPE])
|
||||
.max_age(3600);
|
||||
|
||||
App::new().wrap(cors).service(fetch_ics)
|
||||
})
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Reference in new issue
Block a user