Skip to content

Commit

Permalink
Pin dependencies to versions that are compatible withhttp: 0.2.11 u…
Browse files Browse the repository at this point in the history
…ntil all crates have updated
  • Loading branch information
mre committed Jan 30, 2024
1 parent dc042e1 commit 6427ba1
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 73 deletions.
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[package]
name = "terraphim_ai"
version = "0.1.0"
edition = "2021"

[workspace]
resolver = "2"
members = [
"crates/*",
"terraphim_types",
Expand All @@ -12,4 +8,4 @@ members = [
]
default-members = [
"terraphim_server",
]
]
4 changes: 2 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ install:
source:
FROM +install
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir server-axum desktop crates terraphim_types ./
COPY desktop+build/dist /code/server-axum/dist
COPY --keep-ts --dir terraphim-server desktop crates terraphim_types ./
COPY desktop+build/dist /code/terraphim-server/dist
DO rust+CARGO --args=fetch

cross-build:
Expand Down
2 changes: 1 addition & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ path = "src/bin/main.rs"
name = "terraphim-config"

[dependencies]
opendal = { version = "0.41.0", features = ["services-dashmap", "services-sled","services-atomicserver"] }
opendal = { version = "0.44.2", features = ["services-dashmap", "services-sled","services-atomicserver"] }
tokio = { version = "1.35.1", features = ["full","fs", "macros", "rt-multi-thread"] }
log = "0.4"
tracing = { version = "0.1"}
Expand Down
2 changes: 1 addition & 1 deletion crates/persistence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async-once-cell = "0.5.3"
async-trait = "0.1.74"
dirs = "5.0.0"
log = "0.4"
opendal = { version = "0.41.0", features = [
opendal = { version = "0.44.2", features = [
"services-dashmap",
"services-redis",
"services-sled",
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tauri-build = { version = "1.5.0", features = [] }
terraphim_config= {path="../../crates/config"}
terraphim_middleware = {path="../../crates/middleware" }
terraphim_pipeline= {path="../../crates/terraphim_pipeline"}
terraphim_server= {path = "../../server-axum"}
terraphim_server= {path = "../../terraphim_server"}
terraphim_settings= {path="../../crates/settings"}
terraphim_types= {path="../../terraphim_types"}

Expand Down
2 changes: 1 addition & 1 deletion lab/parking-lot/config-settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ log = "0.4.14"
test-log = "0.2.14"

[dev-dependencies]
opendal = { version = "0.40.0", features = ["services-dashmap", "services-redis", "services-sled"] }
opendal = { version = "0.44.2", features = ["services-dashmap", "services-redis", "services-sled"] }
tempfile = "3.7.1"
13 changes: 8 additions & 5 deletions terraphim_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ terraphim_settings = { path = "../crates/settings" }
terraphim_types = { path = "../terraphim_types" }

anyhow = "1.0.40"
axum = {version ="0.7.4", features = ["macros"]}
axum-extra = {version ="0.6.0"}
axum = {version ="0.6.2", features = ["macros"]}
axum-extra = "0.8.0"
clap = { version = "4.4.18", features = ["derive"] }
log = "0.4.14"
portpicker = "0.1"
Expand All @@ -22,9 +22,12 @@ serde = { version = "1.0.149", features = ["derive"] }
serde_json = "1.0.108"
tokio = { version = "1.35.1", features = ["full"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }
tower-http = { version = "0.2", features = ["cors"] }
tower-http = { version = "0.4.0", features = ["cors", "fs", "trace"] }
ulid = { version = "1.0.0", features = ["serde", "uuid"] }
utoipa = { features = ["axum_extras"], version = "4.1.0" }
utoipa-rapidoc = { version = "*", features = ["axum"] }
utoipa-redoc = { version = "*", features = ["axum"] }
utoipa-rapidoc = { version = "1.0.0", features = ["axum"] }
utoipa-redoc = { version = "1.0.0", features = ["axum"] }
utoipa-swagger-ui = { features = ["axum"], version = "4.0.0" }
tower = "0.4.13"
rust-embed = "8.2.0"
mime_guess = "2.0.4"
2 changes: 1 addition & 1 deletion terraphim_server/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install:
source:
FROM +install
COPY --keep-ts --dir . .
COPY desktop+build/dist /code/server-axum/dist
COPY desktop+build/dist /code/terraphim-server/dist
DO rust+CARGO --args=fetch --keep-fingerprints=true
SAVE ARTIFACT dist as LOCAL /dist

Expand Down
92 changes: 42 additions & 50 deletions terraphim_server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
use axum::{
http::{header,Method,StatusCode,Uri},
http::{header, Method, StatusCode, Uri},
response::{Html, IntoResponse, Response},
routing::{get, post},
Extension, Router,
response::{Html, IntoResponse, Response},
};

use std::net::SocketAddr;
use tower::ServiceExt;
mod api;
use api::{create_article, health_axum, search_articles, search_articles_post};
use portpicker;
use rust_embed::RustEmbed;
use terraphim_pipeline::IndexedDocument;
use terraphim_types as types;
use tokio::sync::broadcast::channel;
use tower_http::cors::{Any, CorsLayer};
use tower_http::{
services::{ServeDir, ServeFile},
trace::TraceLayer,
};

mod error;

pub use error::Result;

use rust_embed::RustEmbed;
// use axum_embed::ServeEmbed;
static INDEX_HTML: &str = "index.html";

#[derive(RustEmbed, Clone)]
#[folder = "dist/"]
struct Assets;


pub async fn axum_server(server_hostname: SocketAddr, config_state: types::ConfigState) {

pub async fn axum_server(
server_hostname: SocketAddr,
config_state: types::ConfigState,
) -> Result<()> {
// let assets = axum_embed::ServeEmbed::<Assets>::with_parameters(Some("index.html".to_owned()),axum_embed::FallbackBehavior::Ok, Some("index.html".to_owned()));
let (tx, _rx) = channel::<IndexedDocument>(10);

Expand Down Expand Up @@ -65,52 +59,50 @@ pub async fn axum_server(server_hostname: SocketAddr, config_state: types::Confi
);

println!("listening on {server_hostname}");
let listener = tokio::net::TcpListener::bind(server_hostname).await.unwrap();
axum::serve(listener, app).await.unwrap();

// axum::Server::bind(&server_hostname)
// .serve(app.into_make_service())
// .await
// .unwrap_or_else(|_| {
// // FIXME: this unwrap is never reached
// // the desired behavior is to pick a new port and try again
// let port = portpicker::pick_unused_port().expect("failed to find unused port");
// let add = SocketAddr::from(([127, 0, 0, 1], port));
// println!("listening on {add} with {port}");
// });
}

// This is the new way to start the server
// However, we can't use it yet, because some crates have not updated
// to `http` 1.0.0 yet.
// let listener = tokio::net::TcpListener::bind(server_hostname).await?;
// axum::serve(listener, app).await?;

axum::Server::bind(&server_hostname)
.serve(app.into_make_service())
.await?;

Ok(())
}

async fn static_handler(uri: Uri) -> impl IntoResponse {
let path = uri.path().trim_start_matches('/');

if path.is_empty() || path == INDEX_HTML {
return index_html().await;
return index_html().await;
}

match Assets::get(path) {
Some(content) => {
let mime = mime_guess::from_path(path).first_or_octet_stream();

([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response()
}
None => {
if path.contains('.') {
return not_found().await;
Some(content) => {
let mime = mime_guess::from_path(path).first_or_octet_stream();

([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response()
}
None => {
if path.contains('.') {
return not_found().await;
}

index_html().await
}

index_html().await
}
}
}
async fn index_html() -> Response {
}

async fn index_html() -> Response {
match Assets::get(INDEX_HTML) {
Some(content) => Html(content.data).into_response(),
None => not_found().await,
Some(content) => Html(content.data).into_response(),
None => not_found().await,
}
}
async fn not_found() -> Response {
}

async fn not_found() -> Response {
(StatusCode::NOT_FOUND, "404").into_response()
}
}
7 changes: 3 additions & 4 deletions terraphim_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
)]
#![deny(anonymous_parameters, macro_use_extern_crate, pointer_structural_match)]
// #![deny(missing_docs)]
use clap::Parser;
use anyhow::Context;
use clap::Parser;
use std::net::SocketAddr;
use std::sync::Arc;
use terraphim_settings::Settings;
Expand All @@ -41,7 +41,6 @@ struct Args {

#[tokio::main]
async fn main() -> Result<()> {

let args = Args::parse();
println!("args: {:?}", args);
let server_settings = Settings::load_from_env_and_file(None)
Expand All @@ -58,7 +57,7 @@ async fn main() -> Result<()> {
let port = portpicker::pick_unused_port().expect("failed to find unused port");
SocketAddr::from(([127, 0, 0, 1], port))
});

let mut config_state = types::ConfigState::new().await?;

// Add one more for testing local KG
Expand All @@ -78,7 +77,7 @@ async fn main() -> Result<()> {
"cfg Roles: {:?}",
config_state.roles.keys().collect::<Vec<&String>>()
);
axum_server(addr, config_state).await;
axum_server(addr, config_state).await?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion terraphim_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraphim_pipeline = { path = "../crates/terraphim_pipeline" }

anyhow = "1.0.0"
log = "0.4.14"
opendal = { version = "0.41.0", features = [
opendal = { version = "0.44.2", features = [
"services-dashmap",
"services-redis",
"services-sled",
Expand Down

0 comments on commit 6427ba1

Please sign in to comment.