pnpm dependencies become crates with build.rs

master
Niko PLP 3 days ago
parent e3faf39ade
commit 814aa22fd4
  1. 16
      Cargo.lock
  2. 2
      Cargo.toml
  3. 20
      helpers/app-auth/Cargo.toml
  4. 15
      helpers/app-auth/build.rs
  5. 1
      helpers/app-auth/package.json
  6. 27
      helpers/app-auth/src/lib.rs
  7. 16
      ng-app/Cargo.toml
  8. 15
      ng-app/build.rs
  9. 27
      ng-app/src/lib.rs
  10. 6
      ng-broker/Cargo.toml
  11. 36
      ng-broker/src/server_ws.rs

16
Cargo.lock generated

@ -3286,6 +3286,20 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ng-app-auth"
version = "0.1.1-alpha.2"
dependencies = [
"rust-embed",
]
[[package]]
name = "ng-app-web"
version = "0.1.1-alpha.2"
dependencies = [
"rust-embed",
]
[[package]]
name = "ng-async-tungstenite"
version = "0.22.2"
@ -3311,6 +3325,8 @@ dependencies = [
"futures",
"getrandom 0.2.10",
"netdev",
"ng-app-auth",
"ng-app-web",
"ng-async-tungstenite",
"ng-client-ws",
"ng-net",

@ -13,11 +13,13 @@ members = [
"ng-sdk-js",
"ng-sdk-python",
"ng-app/src-tauri",
"ng-app",
"ng-oxigraph",
"helpers/wasm-tools",
"helpers/ngnet",
"helpers/ngapp",
"helpers/ngaccount",
"helpers/app-auth",
]
default-members = [ "nextgraph", "ngcli", "ngd" ]

@ -0,0 +1,20 @@
[package]
name = "ng-app-auth"
description = "NextGraph Auth App"
publish = true
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
keywords.workspace = true
documentation.workspace = true
rust-version.workspace = true
#[lib]
#name = "ngappauthlib"
#crate-type = ["rlib"]
[dependencies]
rust-embed= { version = "6.7.0", features=["include-exclude"] }

@ -0,0 +1,15 @@
use std::process::Command;
use std::env;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=src");
let out_dir = env::var("OUT_DIR").unwrap();
//println!("{out_dir}");
//pnpm -C ./helpers/app-auth install
//pnpm -C ./helpers/app-auth build
Command::new("pnpm").args(&["install"]).status().unwrap();
Command::new("pnpm").args(&["buildcargo"]).status().unwrap();
}

@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"buildcargo": "vite build --base=./ && node prepare-app-file.cjs && shx rm -rf ./dist/assets",
"build": "cd ../wasm-tools && cargo run-script app && cd ../app-auth && vite build --base=./ && node prepare-app-file.cjs && shx rm -rf ./dist/assets",
"builddev": "cd ../wasm-tools && cargo run-script app && cd ../app-auth && cross-env NG_DEV=1 vite build --base=./ && shx rm -rf ./dist/assets && shx mkdir -p ../../ng-app/public_dev && cp ./dist/index.html ../../ng-app/public_dev/appauth.html",
"preview": "vite preview"

@ -0,0 +1,27 @@
use rust_embed::{EmbeddedFile, RustEmbed};
use std::path::Path;
#[derive(RustEmbed)]
#[folder = "./dist/"]
#[include = "*.sha256"]
#[include = "*.gzip"]
pub struct AppAuth;
pub fn get_app_auth_sha256() -> EmbeddedFile {
AppAuth::get("index.sha256").unwrap()
}
// pub fn get_app_auth_sha256_bytes() -> &'static [u8] {
// include_bytes!("../dist/index.sha256")
// }
pub fn get_app_auth_gzip() -> EmbeddedFile {
AppAuth::get("index.gzip").unwrap()
}
// pub fn get_app_auth_gzip_bytes() -> &'static [u8] {
// include_bytes!("../dist/index.gzip")
// }

@ -0,0 +1,16 @@
[package]
name = "ng-app-web"
description = "NextGraph Official Web App"
publish = true
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
keywords.workspace = true
documentation.workspace = true
rust-version.workspace = true
[dependencies]
rust-embed= { version = "6.7.0", features=["include-exclude"] }

@ -0,0 +1,15 @@
use std::process::Command;
use std::env;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=src");
let out_dir = env::var("OUT_DIR").unwrap();
//println!("{out_dir}");
//pnpm -C ./helpers/app-auth install
//pnpm -C ./helpers/app-auth build
Command::new("pnpm").args(&["install"]).status().unwrap();
Command::new("pnpm").args(&["webfilebuild"]).status().unwrap();
}

@ -0,0 +1,27 @@
use rust_embed::{EmbeddedFile, RustEmbed};
use std::path::Path;
#[derive(RustEmbed)]
#[folder = "./dist-file/"]
#[include = "*.sha256"]
#[include = "*.gzip"]
pub struct AppWeb;
pub fn get_app_web_sha256() -> EmbeddedFile {
AppWeb::get("index.sha256").unwrap()
}
// pub fn get_app_auth_sha256_bytes() -> &'static [u8] {
// include_bytes!("../dist/index.sha256")
// }
pub fn get_app_web_gzip() -> EmbeddedFile {
AppWeb::get("index.gzip").unwrap()
}
// pub fn get_app_auth_gzip_bytes() -> &'static [u8] {
// include_bytes!("../dist/index.gzip")
// }

@ -24,14 +24,16 @@ either = { version = "1.8.1", features=["serde"] }
async-std = { version = "1.12.0", features = ["attributes"] }
async-trait = "0.1.64"
rust-embed= { version = "6.7.0", features=["include-exclude"] }
ng-async-tungstenite = { version = "0.22.2", git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = ["async-std-runtime"] }
urlencoding = "2.1.3"
blake3 = "1.3.1"
ng-async-tungstenite = { version = "0.22.2", git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = ["async-std-runtime"] }
ng-repo = { path = "../ng-repo", version = "0.1.1-alpha.2" }
ng-net = { path = "../ng-net", version = "0.1.1-alpha.2" }
ng-client-ws = { path = "../ng-client-ws", version = "0.1.1-alpha.2" }
ng-verifier = { path = "../ng-verifier", version = "0.1.1-alpha.2" }
ng-storage-rocksdb = { path = "../ng-storage-rocksdb", version = "0.1.1-alpha.2" }
urlencoding = "2.1.3"
ng-app-auth = { path = "../helpers/app-auth", version = "0.1.1-alpha.2" }
ng-app-web = { path = "../ng-app", version = "0.1.1-alpha.2" }
[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom]
version = "0.2.7"

@ -46,6 +46,10 @@ use ng_net::NG_BOOTSTRAP_LOCAL_PATH;
use ng_client_ws::remote_ws::ConnectionWebSocket;
use ng_app_auth::{get_app_auth_gzip, get_app_auth_sha256};
use ng_app_web::{get_app_web_gzip, get_app_web_sha256};
use crate::interfaces::*;
use crate::rocksdb_server_storage::RocksDbServerStorage;
use crate::server_broker::ServerBroker;
@ -207,20 +211,20 @@ fn prepare_urls_from_private_addrs(addrs: &Vec<BindAddress>, port: u16) -> Vec<S
// struct AppAuth;
#[cfg(not(docsrs))]
#[derive(RustEmbed)]
#[folder = "./static/app/"]
#[include = "*.sha256"]
#[include = "*.gzip"]
struct App;
// #[cfg(not(docsrs))]
// #[derive(RustEmbed)]
// #[folder = "./static/app/"]
// #[include = "*.sha256"]
// #[include = "*.gzip"]
// struct App;
#[cfg(not(docsrs))]
#[derive(RustEmbed)]
#[folder = "./static/app-auth/"]
#[include = "*.sha256"]
#[include = "*.gzip"]
// #[cfg(not(docsrs))]
// #[derive(RustEmbed)]
// #[folder = "./static/app-auth/"]
// #[include = "*.sha256"]
// #[include = "*.gzip"]
struct AppAuth;
// struct AppAuth;
#[derive(RustEmbed)]
#[folder = "src/public/"]
@ -251,7 +255,7 @@ fn upgrade_ws_or_serve_app(
if serve_app && (remote.is_private() || remote.is_loopback()) {
if uri == "/" {
log_debug!("Serving the app");
let sha_file = App::get("index.sha256").unwrap();
let sha_file = get_app_web_sha256();
let sha = format!(
"\"{}\"",
std::str::from_utf8(sha_file.data.as_ref()).unwrap()
@ -266,7 +270,7 @@ fn upgrade_ws_or_serve_app(
.unwrap();
return Err(res);
}
let file = App::get("index.gzip").unwrap();
let file = get_app_web_gzip();
let res = Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "text/html")
@ -296,7 +300,7 @@ fn upgrade_ws_or_serve_app(
},
None => {return Err(make_error(StatusCode::BAD_REQUEST))}
};
let sha_file = AppAuth::get("index.sha256").unwrap();
let sha_file = get_app_auth_sha256();
let sha = format!(
"\"{}\"",
std::str::from_utf8(sha_file.data.as_ref()).unwrap()
@ -313,7 +317,7 @@ fn upgrade_ws_or_serve_app(
.unwrap();
return Err(res);
}
let file = AppAuth::get("index.gzip").unwrap();
let file = get_app_auth_gzip();
let res = Response::builder().status(StatusCode::OK)
.header("Content-Security-Policy", format!("frame-ancestors 'self' https://nextgraph.net {webapp_origin};"))
.header("X-Frame-Options", format!("ALLOW-FROM {webapp_origin}"))

Loading…
Cancel
Save