Skip to content

Commit

Permalink
Merge pull request #9 from opeolluwa/monorepo
Browse files Browse the repository at this point in the history
Monorepo
  • Loading branch information
opeolluwa authored Nov 10, 2023
2 parents 43b0c20 + e89a7ca commit 6156e8b
Show file tree
Hide file tree
Showing 53 changed files with 6,343 additions and 333 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?
core/server/assets

.nx/cache
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Skylite

![skylite](./skylite.png)

- [Description](#description)
- [Getting Started](#getting-started)
- [Dependencies](#dependencies)
Expand Down
16 changes: 0 additions & 16 deletions README.md.bak

This file was deleted.

24 changes: 12 additions & 12 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "0.0.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["server", "ipc", "utils"]
members = ["server", "command", "utils"]

[workspace.dependencies]
lazy_static = "1.4.0"
Expand All @@ -22,12 +22,12 @@ tauri = {version = "1.2", features = ["api-all"] }
tauri-build = {version = "1.2", features = [] }

[dependencies]
ipc = {path = "./ipc"}
command = {path = "./command"}
lazy_static = "1.4.0"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
server = {path = "./server"}
tauri = {version = "1.2", features = [ "dialog-message", "process-relaunch", "process-exit", "shell-open"] }
tauri = {version = "1.2", features = ["dialog-message", "process-relaunch", "process-exit", "shell-open"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions core/ipc/Cargo.toml → core/command/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "ipc"
version = "0.1.0"
name = "command"
version = "1.0.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -10,4 +10,4 @@ local-ip-address = "0.5.6"
serde = {workspace = true}
serde_json = {workspace = true}
tauri = {workspace = true}
utils = { version = "0.1.0", path = "../utils" }
utils = { path = "../utils" }
File renamed without changes.
13 changes: 13 additions & 0 deletions core/command/src/server_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::net::{IpAddr, Ipv4Addr};

use local_ip_address::local_ip;
use utils::pkg::CommandData;

#[tauri::command]
pub fn server() -> CommandData<String> {
let default_ip_address = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
let local_ip = local_ip().unwrap_or(default_ip_address);
let port = 2105;
let server_address = format!("http://{}:{}", local_ip, port);
CommandData::ok("server address", server_address)
}
13 changes: 13 additions & 0 deletions core/command/src/wifi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use local_ip_address::local_ip;
use utils::pkg::CommandData;

#[tauri::command]
pub fn is_connected_to_wifi() -> CommandData<bool> {
// the app would have a local ip address if it is connected to a network
// else it would crash, this is leveraged to check the network status
let has_ip_addr = local_ip().ok();
if has_ip_addr.is_none() {
return CommandData::ok("wifi status", false);
}
CommandData::ok("server address", true)
}
10 changes: 0 additions & 10 deletions core/ipc/src/server_address.rs

This file was deleted.

7 changes: 0 additions & 7 deletions core/ipc/src/wifi.rs

This file was deleted.

36 changes: 22 additions & 14 deletions core/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::net::IpAddr;
use std::net::Ipv4Addr;

use axum::http::HeaderValue;
use reqwest::Method;

use tower_http::cors::Any;
use tower_http::cors::CorsLayer;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;


use axum::extract::DefaultBodyLimit;
use local_ip_address::local_ip;

Expand All @@ -16,13 +18,26 @@ mod routes;

lazy_static! {
/**
* the lazy static crate allow the lazy evaluation of constants thus, one can bypass the impossible dynamic bindings of constants
* the lazy static crate allow the lazy evaluation of constants thus, one can bypass the impossible dynamic bindings of constants and static variables
*
*
* Herein the server port made globally available, this allow for ease of sharing same with file upload directory
*
*/
pub static ref SERVER_PORT: u16 = 2105;
// the directory the files would be uploaded to
pub static ref UPLOAD_DIRECTORY: std::string::String = String::from("skylite");

/** // the server address
* run the web server on the device Ip address,
* if the address is not found, fallback to 0.0.0.0:2105
*/
pub static ref SERVER_ADDRESS: std::string::String = {

let default_ip_address = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
let local_ip = local_ip().unwrap_or(default_ip_address);
format!("{:?}:{:?}", local_ip, *SERVER_PORT as u64)
};
}

/**
Expand All @@ -31,7 +46,6 @@ lazy_static! {
* machine and file download to the host machine
*/
pub async fn run() {
// initialize database
// initialize tracing subscriber
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(
Expand All @@ -41,38 +55,32 @@ pub async fn run() {
.init(); // allow debugging in development set up

// define cors scope as any
// change this later to only allow get and post http verbs
let allowed_origin = SERVER_ADDRESS.parse::<HeaderValue>().unwrap();
let cors_layer = CorsLayer::new()
.allow_headers(Any)
.allow_methods([Method::GET, Method::POST]) // restrict methods
.allow_origin(Any); // TODO: restrict this in the future to only sendfile proxy server for example http://sendfile/dhsdo
// restrict the service to only devices on the network
.allow_origin(allowed_origin);

// define file limit layer as 10GB
// see information here <https://docs.rs/axum/0.6.2/axum/extract/struct.DefaultBodyLimit.html#%E2%80%A6>
let file_size_limit = 10 * 1024 * 1024 * 1024;
let file_limit = DefaultBodyLimit::max(file_size_limit);



// run the https server on localhost then feed off the connection using the wifi gateway, the same way Vite/Vue CLI would do the core server
// this is currently achieved by binding the server to the device default ip address
let my_local_ip = local_ip().unwrap();
let ip_address = format!("{:?}:{:?}", my_local_ip, *SERVER_PORT as u64);
let ip_address = ip_address
let ip_address = SERVER_ADDRESS
.parse::<std::net::SocketAddr>()
.expect("invalid socket address");

println!("server running on http://{}", &ip_address.to_string());

// build our application with the required routes
let app = router::app()
/* .fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true)) */
/* .fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true)) */
.layer(file_limit)
.layer(cors_layer)
.layer(tower_http::trace::TraceLayer::new_for_http());
// .fallback(handle_404);


// run the server
axum::Server::bind(&ip_address)
.serve(app.into_make_service())
Expand Down
4 changes: 2 additions & 2 deletions core/server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use axum::{

use tower_http::services::ServeDir;

use crate::routes::{accept_file_upload, download_file, file_upload_form, get_file};
use crate::routes::{accept_file_upload, download_file, get_file};

// the app is moved here to allow sharing across test modules
pub fn app() -> Router {
let assets_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("views");

Router::new()
.route("/", post(accept_file_upload).get(file_upload_form))
.route("/upload", post(accept_file_upload))
.route("/api/download", get(download_file))
.route("/api/file", get(get_file))
.fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true))
Expand Down
Loading

0 comments on commit 6156e8b

Please sign in to comment.