Skip to content

Commit

Permalink
Fix bugs in kiss-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Aug 31, 2022
1 parent 0acebd7 commit c1ee4d2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Temporary
**/http-cacache/

# CI/CD
/.dockerignore
/.github/
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Temporary
**/http-cacache/

# Editor
/.vscode/
**/tmp/
3 changes: 1 addition & 2 deletions kiss/assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ ipis = { git = "https://github.com/ulagbulag-village/ipis" }
kiss-api = { path = "../api" }

actix-web = { version = "4.1", features = ["experimental-io-uring"] }
http-cache-reqwest = "0.5"
reqwest = { version = "0.11", default-features = false, features = [
"rustls",
"rustls-tls",
"stream",
] }
reqwest-middleware = "0.1"
22 changes: 5 additions & 17 deletions kiss/assets/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use actix_web::{
web::{BytesMut, Data, Path, Payload},
App, HttpRequest, HttpResponse, HttpServer, Responder,
};
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache};
use ipis::{
env::infer,
futures::StreamExt,
Expand Down Expand Up @@ -98,12 +97,7 @@ async fn resolve(
builder.no_chunking(content_length);
}

// the response is already cached
match res.bytes().await {
Ok(body) => builder.body(body),
Err(e) => HttpResponse::Forbidden()
.body(format!("failed to download from url {path:?}: {e}")),
}
builder.streaming(res.bytes_stream())
}
Err(e) => {
HttpResponse::Forbidden().body(format!("failed to find the url {path:?}: {e}"))
Expand All @@ -118,18 +112,12 @@ async fn resolve(
async fn main() {
async fn try_main() -> ::ipis::core::anyhow::Result<()> {
// Initialize config
let addr = infer::<_, SocketAddr>("BIND_ADDR")
.unwrap_or_else(|_| "0.0.0.0:80".parse().unwrap());
let addr =
infer::<_, SocketAddr>("BIND_ADDR").unwrap_or_else(|_| "0.0.0.0:80".parse().unwrap());
let config = Arc::new(ProxyConfig::load().await?);

// Initialize cache client
let client = ClientBuilder::new(Client::new())
.with(Cache(HttpCache {
mode: CacheMode::Default,
manager: CACacheManager::default(),
options: None,
}))
.build();
// Initialize client
let client = ClientBuilder::new(Client::new()).build();

// Start web server
HttpServer::new(move || {
Expand Down
2 changes: 1 addition & 1 deletion templates/kiss/kiss-assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
memory: 20Mi
limits:
cpu: 100m
memory: 4Gi
memory: 100Mi
volumeMounts:
- name: config
mountPath: /etc/netai-cloud/kiss/assets
Expand Down

0 comments on commit c1ee4d2

Please sign in to comment.