Skip to content

Commit

Permalink
fix: update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
muandane committed Jun 28, 2024
1 parent 372d47a commit 42f1d4b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 403 deletions.
387 changes: 7 additions & 380 deletions apps/mule/Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions apps/mule/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ debug = 0
strip = "debuginfo"

[dependencies]
hyper = { version = "0.14", features =["http1", "server", "tcp"]}
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"
sha2 = "0.9"
hyper = { version = "0.14", features = ["http1", "server", "tcp"] }
tokio = { version = "1", features = ["fs", "io-util", "macros", "rt-multi-thread", "signal"] }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", features = ["fmt"], default-features = false }
sha2 = { version = "0.9", default-features = false }
serde_json = "1.0.117"
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "sqlite"] }
reqwest = { version = "0.12.5", features = ["json"] }
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls","sqlite"], default-features = false }
reqwest = { version = "0.12.5",features = ["json"] }
9 changes: 5 additions & 4 deletions apps/mule/src/handlers/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tokio::io::AsyncReadExt;
use std::path::PathBuf;
use std::convert::Infallible;
use tracing::info;
use crate::utils::with_cors;

pub async fn serve_file(req: Request<Body>, _cache: crate::cache::Cache) -> Result<Response<Body>, Infallible> {
let cdn_root = std::env::var("CDN_ROOT").unwrap_or_else(|_| {
Expand All @@ -19,18 +20,18 @@ pub async fn serve_file(req: Request<Body>, _cache: crate::cache::Cache) -> Resu
Ok(mut file) => {
let mut contents = Vec::new();
if let Err(_e) = file.read_to_end(&mut contents).await {
return Ok(Response::builder()
return Ok(with_cors(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("Internal Server Error"))
.unwrap());
.unwrap()));
}
Ok(Response::new(Body::from(contents)))
}
Err(_) => {
Ok(Response::builder()
Ok(with_cors(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("File Not Found"))
.unwrap())
.unwrap()))
}
}
}
9 changes: 5 additions & 4 deletions apps/mule/src/handlers/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde_json::json;
use sha2::{Sha256, Digest};
use tokio::fs;
use tokio::io::AsyncWriteExt;
use crate::utils::with_cors;

pub async fn cache_file(cdn_root: String,req: Request<Body>, db: DbPool) -> Result<Response<Body>, Infallible> {
let whole_body = hyper::body::to_bytes(req.into_body()).await.unwrap();
Expand All @@ -22,14 +23,14 @@ pub async fn cache_file(cdn_root: String,req: Request<Body>, db: DbPool) -> Resu

add_to_cache(db, &hash, &url).await;
info!("Cached file '{}' with hash '{}'", &url, &hash);
Ok(Response::new(Body::from("Cached successfully")))
Ok(with_cors(Response::new(Body::from("Cached successfully"))))
},
Err(err) => {
error!("Failed to fetch the URL: {}", err);
Ok(Response::builder()
Ok(with_cors(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Body::from("Failed to fetch the URL"))
.unwrap())
.unwrap()))
}
}
}
Expand All @@ -38,5 +39,5 @@ pub async fn get_cache_mapping(_req: Request<Body>, db: DbPool) -> Result<Respon
let mappings = fetch_mappings(db).await;
let json = json!(mappings);

Ok(Response::new(Body::from(json.to_string())))
Ok(with_cors(Response::new(Body::from(json.to_string()))))
}
1 change: 1 addition & 0 deletions apps/mule/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod cache;
mod config;
mod shutdown;
mod db;
mod utils;

use handlers::file::serve_file;
use handlers::management::{cache_file, get_cache_mapping};
Expand Down
9 changes: 9 additions & 0 deletions apps/mule/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use hyper::{Response, Body, header};

pub fn with_cors(response: Response<Body>) -> Response<Body> {
let (mut parts, body) = response.into_parts();
parts.headers.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, header::HeaderValue::from_static("*"));
parts.headers.insert(header::ACCESS_CONTROL_ALLOW_METHODS, header::HeaderValue::from_static("GET, POST, OPTIONS"));
parts.headers.insert(header::ACCESS_CONTROL_ALLOW_HEADERS, header::HeaderValue::from_static("Content-Type"));
Response::from_parts(parts, body)
}
10 changes: 5 additions & 5 deletions apps/wopper/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script>
/*const backgroundUrl = import.meta.env.VITE_EPIC_GIF;
const imageText = import.meta.env.VITE_EPIC_NAME;*/
const backgroundUrl = import.meta.env.VITE_EPIC_GIF;
const imageText = import.meta.env.VITE_EPIC_NAME;
// import 'dotenv/config';
// const backgroundUrl = import.meta.env.VITE_EPIC_GIF;
// const imageText = import.meta.env.VITE_EPIC_NAME;
import 'dotenv/config';
import LatencyCounter from './HUD.svelte';
// const backgroundUrl = process.env.PUBLIC_EPIC_GIF;
// const imageText = process.env.PUBLIC_EPIC_NAME;
const backgroundUrl = process.env.PUBLIC_EPIC_GIF;
const imageText = process.env.PUBLIC_EPIC_NAME;
</script>


Expand Down
5 changes: 2 additions & 3 deletions apps/wopper/src/routes/HUD.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* @type {string | null}
*/
let serverLocation = null;
async function measureLatency() {
try {
console.log('Measuring latency for:', backgroundUrl);
Expand All @@ -42,13 +41,13 @@
const data = await response.json();
serverLocation = data.timezone;
} catch (error) {
// @ts-ignore
console.error('Error measuring latency:', error.message);
console.error('Error measuring latency:', error);
latency = serverLatency = -1;
serverLocation = 'Error';
}
}
onMount(measureLatency);
</script>

Expand Down

0 comments on commit 42f1d4b

Please sign in to comment.