chatgpt example proxy server

This commit is contained in:
lda committed 2025-05-16 02:10:24 +07:00
commit 0b44c6afe2
4 files changed
+2345

No files matched your search

+1
View File
@@ -0,0 +1 @@
/target
Generated
+2294
View File
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "cal_filter"
version = "0.1.0"
edition = "2024"
publish = ["gitea"]
[dependencies]
actix-cors = "0.7"
actix-web = "4"
reqwest = {version = "0.12", features = ["blocking"]}
tokio = { version = "1.45.0", features = ["full"] }
+39
View File
@@ -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
}