Skip to content

Commit 6156e8b

Browse files
authored
Merge pull request #9 from opeolluwa/monorepo
Monorepo
2 parents 43b0c20 + e89a7ca commit 6156e8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6343
-333
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
core/server/assets
26+
27+
.nx/cache

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Skylite
22

3+
![skylite](./skylite.png)
4+
35
- [Description](#description)
46
- [Getting Started](#getting-started)
57
- [Dependencies](#dependencies)

README.md.bak

Lines changed: 0 additions & 16 deletions
This file was deleted.

core/Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version = "0.0.0"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[workspace]
13-
members = ["server", "ipc", "utils"]
13+
members = ["server", "command", "utils"]
1414

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

2424
[dependencies]
25-
ipc = {path = "./ipc"}
25+
command = {path = "./command"}
2626
lazy_static = "1.4.0"
2727
serde = {version = "1.0", features = ["derive"] }
2828
serde_json = "1.0"
2929
server = {path = "./server"}
30-
tauri = {version = "1.2", features = [ "dialog-message", "process-relaunch", "process-exit", "shell-open"] }
30+
tauri = {version = "1.2", features = ["dialog-message", "process-relaunch", "process-exit", "shell-open"] }
3131
[features]
3232
# this feature is used for production builds or when `devPath` points to the filesystem
3333
# DO NOT REMOVE!!
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
3-
name = "ipc"
4-
version = "0.1.0"
3+
name = "command"
4+
version = "1.0.5"
55

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

@@ -10,4 +10,4 @@ local-ip-address = "0.5.6"
1010
serde = {workspace = true}
1111
serde_json = {workspace = true}
1212
tauri = {workspace = true}
13-
utils = { version = "0.1.0", path = "../utils" }
13+
utils = { path = "../utils" }
File renamed without changes.

core/command/src/server_address.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::net::{IpAddr, Ipv4Addr};
2+
3+
use local_ip_address::local_ip;
4+
use utils::pkg::CommandData;
5+
6+
#[tauri::command]
7+
pub fn server() -> CommandData<String> {
8+
let default_ip_address = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
9+
let local_ip = local_ip().unwrap_or(default_ip_address);
10+
let port = 2105;
11+
let server_address = format!("http://{}:{}", local_ip, port);
12+
CommandData::ok("server address", server_address)
13+
}

core/command/src/wifi.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use local_ip_address::local_ip;
2+
use utils::pkg::CommandData;
3+
4+
#[tauri::command]
5+
pub fn is_connected_to_wifi() -> CommandData<bool> {
6+
// the app would have a local ip address if it is connected to a network
7+
// else it would crash, this is leveraged to check the network status
8+
let has_ip_addr = local_ip().ok();
9+
if has_ip_addr.is_none() {
10+
return CommandData::ok("wifi status", false);
11+
}
12+
CommandData::ok("server address", true)
13+
}

core/ipc/src/server_address.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/ipc/src/wifi.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

core/server/src/lib.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
use std::net::IpAddr;
2+
use std::net::Ipv4Addr;
13

4+
use axum::http::HeaderValue;
25
use reqwest::Method;
36

47
use tower_http::cors::Any;
58
use tower_http::cors::CorsLayer;
69
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
710
use tracing_subscriber::util::SubscriberInitExt;
811

9-
1012
use axum::extract::DefaultBodyLimit;
1113
use local_ip_address::local_ip;
1214

@@ -16,13 +18,26 @@ mod routes;
1618

1719
lazy_static! {
1820
/**
19-
* the lazy static crate allow the lazy evaluation of constants thus, one can bypass the impossible dynamic bindings of constants
21+
* the lazy static crate allow the lazy evaluation of constants thus, one can bypass the impossible dynamic bindings of constants and static variables
2022
*
2123
*
2224
* Herein the server port made globally available, this allow for ease of sharing same with file upload directory
25+
*
2326
*/
2427
pub static ref SERVER_PORT: u16 = 2105;
28+
// the directory the files would be uploaded to
2529
pub static ref UPLOAD_DIRECTORY: std::string::String = String::from("skylite");
30+
31+
/** // the server address
32+
* run the web server on the device Ip address,
33+
* if the address is not found, fallback to 0.0.0.0:2105
34+
*/
35+
pub static ref SERVER_ADDRESS: std::string::String = {
36+
37+
let default_ip_address = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
38+
let local_ip = local_ip().unwrap_or(default_ip_address);
39+
format!("{:?}:{:?}", local_ip, *SERVER_PORT as u64)
40+
};
2641
}
2742

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

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

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

55-
56-
57-
// 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
58-
// this is currently achieved by binding the server to the device default ip address
59-
let my_local_ip = local_ip().unwrap();
60-
let ip_address = format!("{:?}:{:?}", my_local_ip, *SERVER_PORT as u64);
61-
let ip_address = ip_address
70+
let ip_address = SERVER_ADDRESS
6271
.parse::<std::net::SocketAddr>()
6372
.expect("invalid socket address");
6473

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

6776
// build our application with the required routes
6877
let app = router::app()
69-
/* .fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true)) */
78+
/* .fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true)) */
7079
.layer(file_limit)
7180
.layer(cors_layer)
7281
.layer(tower_http::trace::TraceLayer::new_for_http());
7382
// .fallback(handle_404);
7483

75-
7684
// run the server
7785
axum::Server::bind(&ip_address)
7886
.serve(app.into_make_service())

core/server/src/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use axum::{
77

88
use tower_http::services::ServeDir;
99

10-
use crate::routes::{accept_file_upload, download_file, file_upload_form, get_file};
10+
use crate::routes::{accept_file_upload, download_file, get_file};
1111

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

1616
Router::new()
17-
.route("/", post(accept_file_upload).get(file_upload_form))
17+
.route("/upload", post(accept_file_upload))
1818
.route("/api/download", get(download_file))
1919
.route("/api/file", get(get_file))
2020
.fallback_service(ServeDir::new(assets_dir).append_index_html_on_directories(true))

0 commit comments

Comments
 (0)