@ionyx-apps/cli 0.3.3 โ 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ionyx.exe +0 -0
- package/ionyx-cli/Cargo.toml +3 -2
- package/ionyx-cli/src/commands/build.rs +53 -53
- package/ionyx-cli/src/templates/basic/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/basic/src-ionyx/src/protocol.rs +40 -38
- package/ionyx-cli/src/templates/leptos/Cargo.toml +1 -2
- package/ionyx-cli/src/templates/leptos/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/leptos/src-ionyx/src/protocol.rs +41 -38
- package/ionyx-cli/src/templates/mod.rs +2 -2
- package/ionyx-cli/src/templates/react/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/react/src-ionyx/src/protocol.rs +40 -38
- package/ionyx-cli/src/templates/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/svelte/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/svelte/src-ionyx/src/protocol.rs +40 -38
- package/ionyx-cli/src/templates/vanilla/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/vanilla/src-ionyx/src/protocol.rs +40 -38
- package/ionyx-cli/src/templates/vue/src-ionyx/Cargo.toml +1 -3
- package/ionyx-cli/src/templates/vue/src-ionyx/src/protocol.rs +51 -30
- package/package.json +1 -1
- package/ionyx-cli/src/templates/basic/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/leptos/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/react/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/svelte/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/vanilla/src-ionyx/build.rs +0 -11
- package/ionyx-cli/src/templates/vue/src-ionyx/build.rs +0 -11
package/bin/ionyx.exe
CHANGED
|
Binary file
|
package/ionyx-cli/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "ionyx-cli"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "Ionyx Framework CLI Tool"
|
|
6
6
|
authors = ["Ionyx Team"]
|
|
@@ -23,10 +23,11 @@ handlebars = "4.5"
|
|
|
23
23
|
zip = "0.6"
|
|
24
24
|
reqwest = { version = "0.11", features = ["json"] }
|
|
25
25
|
futures = "0.3"
|
|
26
|
-
include_dir = "0.7"
|
|
27
26
|
dialoguer = "0.11"
|
|
28
27
|
os_info = "3.8"
|
|
29
28
|
toml = "0.8"
|
|
29
|
+
include_dir = "0.7"
|
|
30
|
+
|
|
30
31
|
[workspace]
|
|
31
32
|
exclude = [
|
|
32
33
|
"src/templates/basic/src-ionyx",
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
use anyhow::Result;
|
|
2
|
-
use colored::*;
|
|
3
|
-
use tokio::process::Command;
|
|
4
|
-
use std::path::Path;
|
|
5
|
-
|
|
6
|
-
pub async fn execute(target: &str, minify: bool) -> Result<()> {
|
|
7
|
-
println!("๐จ Building Ionyx project for target: {}", target.cyan());
|
|
8
|
-
|
|
9
|
-
if !Path::new("package.json").exists() {
|
|
10
|
-
return Err(anyhow::anyhow!("No package.json found. Please run this command in an Ionyx project directory."));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 1. Build Frontend
|
|
14
|
-
println!("๐ Building frontend...");
|
|
15
|
-
let fe_status = if cfg!(target_os = "windows") {
|
|
16
|
-
Command::new("cmd")
|
|
17
|
-
.args(&["/C", "npm", "run", "build"])
|
|
18
|
-
.env("BUILD_TARGET", target)
|
|
19
|
-
.env("MINIFY", if minify { "true" } else { "false" })
|
|
20
|
-
.status()
|
|
21
|
-
.await?
|
|
22
|
-
} else {
|
|
23
|
-
Command::new("npm")
|
|
24
|
-
.args(&["run", "build"])
|
|
25
|
-
.env("BUILD_TARGET", target)
|
|
26
|
-
.env("MINIFY", if minify { "true" } else { "false" })
|
|
27
|
-
.status()
|
|
28
|
-
.await?
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
if !fe_status.success() {
|
|
32
|
-
return Err(anyhow::anyhow!("Frontend build failed"));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 2. Build Backend
|
|
36
|
-
println!("๐ฆ Building Rust backend host...");
|
|
37
|
-
let mut be_cmd = Command::new("cargo");
|
|
38
|
-
be_cmd.args(&["build", "--release"]);
|
|
39
|
-
|
|
40
|
-
if Path::new("src-ionyx").exists() {
|
|
41
|
-
be_cmd.current_dir("src-ionyx");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let be_status = be_cmd.status().await?;
|
|
45
|
-
if !be_status.success() {
|
|
46
|
-
return Err(anyhow::anyhow!("Backend build failed"));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
println!("\nโ
Full build completed successfully!");
|
|
50
|
-
println!("๐ฆ Backend binary: src-ionyx/target/release/ionyx-host");
|
|
51
|
-
|
|
52
|
-
Ok(())
|
|
53
|
-
}
|
|
1
|
+
use anyhow::Result;
|
|
2
|
+
use colored::*;
|
|
3
|
+
use tokio::process::Command;
|
|
4
|
+
use std::path::Path;
|
|
5
|
+
|
|
6
|
+
pub async fn execute(target: &str, minify: bool) -> Result<()> {
|
|
7
|
+
println!("๐จ Building Ionyx project for target: {}", target.cyan());
|
|
8
|
+
|
|
9
|
+
if !Path::new("package.json").exists() {
|
|
10
|
+
return Err(anyhow::anyhow!("No package.json found. Please run this command in an Ionyx project directory."));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 1. Build Frontend
|
|
14
|
+
println!("๐ Building frontend...");
|
|
15
|
+
let fe_status = if cfg!(target_os = "windows") {
|
|
16
|
+
Command::new("cmd")
|
|
17
|
+
.args(&["/C", "npm", "run", "build"])
|
|
18
|
+
.env("BUILD_TARGET", target)
|
|
19
|
+
.env("MINIFY", if minify { "true" } else { "false" })
|
|
20
|
+
.status()
|
|
21
|
+
.await?
|
|
22
|
+
} else {
|
|
23
|
+
Command::new("npm")
|
|
24
|
+
.args(&["run", "build"])
|
|
25
|
+
.env("BUILD_TARGET", target)
|
|
26
|
+
.env("MINIFY", if minify { "true" } else { "false" })
|
|
27
|
+
.status()
|
|
28
|
+
.await?
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if !fe_status.success() {
|
|
32
|
+
return Err(anyhow::anyhow!("Frontend build failed"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 2. Build Backend
|
|
36
|
+
println!("๐ฆ Building Rust backend host...");
|
|
37
|
+
let mut be_cmd = Command::new("cargo");
|
|
38
|
+
be_cmd.args(&["build", "--release"]);
|
|
39
|
+
|
|
40
|
+
if Path::new("src-ionyx").exists() {
|
|
41
|
+
be_cmd.current_dir("src-ionyx");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let be_status = be_cmd.status().await?;
|
|
45
|
+
if !be_status.success() {
|
|
46
|
+
return Err(anyhow::anyhow!("Backend build failed"));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
println!("\nโ
Full build completed successfully!");
|
|
50
|
+
println!("๐ฆ Backend binary: src-ionyx/target/release/ionyx-host");
|
|
51
|
+
|
|
52
|
+
Ok(())
|
|
53
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -16,7 +15,6 @@ path = "main.rs"
|
|
|
16
15
|
|
|
17
16
|
[dependencies]
|
|
18
17
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
19
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
20
18
|
anyhow = "1.0"
|
|
21
19
|
wry = "0.54"
|
|
22
20
|
tao = "0.34"
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#[cfg(not(debug_assertions))]
|
|
6
|
-
use include_dir::{include_dir, Dir};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
7
5
|
|
|
8
6
|
// Configuration'dan frontendDist path'ini oku
|
|
9
|
-
fn get_frontend_dist_path() ->
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
10
8
|
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
11
9
|
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
12
10
|
for line in config_content.lines() {
|
|
13
11
|
if line.trim().starts_with("frontendDist") {
|
|
14
|
-
if let Some(
|
|
15
|
-
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Varsayฤฑlan path
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#[cfg(not(debug_assertions))]
|
|
28
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
pub struct CustomProtocolHandler;
|
|
31
34
|
|
|
@@ -35,9 +38,11 @@ impl CustomProtocolHandler {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
38
43
|
#[cfg(debug_assertions)]
|
|
39
44
|
{
|
|
40
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
41
46
|
let _dist_path = get_frontend_dist_path();
|
|
42
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
43
48
|
return Response::builder()
|
|
@@ -49,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
49
54
|
|
|
50
55
|
#[cfg(not(debug_assertions))]
|
|
51
56
|
{
|
|
52
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
53
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
54
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
59
72
|
Response::builder()
|
|
60
73
|
.status(StatusCode::OK)
|
|
61
|
-
.header("Content-Type",
|
|
62
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
63
81
|
.unwrap()
|
|
64
|
-
}
|
|
65
|
-
None => {
|
|
66
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
67
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
68
|
-
Response::builder()
|
|
69
|
-
.status(StatusCode::OK)
|
|
70
|
-
.header("Content-Type", "text/html")
|
|
71
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
72
|
-
.unwrap()
|
|
73
|
-
} else {
|
|
74
|
-
Response::builder()
|
|
75
|
-
.status(StatusCode::NOT_FOUND)
|
|
76
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
77
|
-
.unwrap()
|
|
78
|
-
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -97,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
97
100
|
_ => "application/octet-stream",
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
103
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "my-ionyx-app"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
11
10
|
leptos = { version = "0.6", features = ["csr"] }
|
|
12
11
|
wasm-bindgen = "0.2"
|
|
13
12
|
console_log = "1.0"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -12,7 +11,6 @@ path = "main.rs"
|
|
|
12
11
|
|
|
13
12
|
[dependencies]
|
|
14
13
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
15
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
16
14
|
anyhow = "1.0"
|
|
17
15
|
wry = "0.54"
|
|
18
16
|
tao = "0.34"
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#[cfg(not(debug_assertions))]
|
|
6
|
-
use include_dir::{include_dir, Dir};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
7
5
|
|
|
8
6
|
// Configuration'dan frontendDist path'ini oku
|
|
9
|
-
fn get_frontend_dist_path() ->
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
10
8
|
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
11
9
|
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
12
10
|
for line in config_content.lines() {
|
|
13
11
|
if line.trim().starts_with("frontendDist") {
|
|
14
|
-
if let Some(
|
|
15
|
-
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Varsayฤฑlan path
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#[cfg(not(debug_assertions))]
|
|
28
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
pub struct CustomProtocolHandler;
|
|
31
34
|
|
|
@@ -35,9 +38,12 @@ impl CustomProtocolHandler {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
38
43
|
#[cfg(debug_assertions)]
|
|
39
44
|
{
|
|
40
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
46
|
+
let _dist_path = get_frontend_dist_path();
|
|
41
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
42
48
|
return Response::builder()
|
|
43
49
|
.status(StatusCode::NOT_FOUND)
|
|
@@ -48,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
48
54
|
|
|
49
55
|
#[cfg(not(debug_assertions))]
|
|
50
56
|
{
|
|
51
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
52
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
53
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
58
72
|
Response::builder()
|
|
59
73
|
.status(StatusCode::OK)
|
|
60
|
-
.header("Content-Type",
|
|
61
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
62
81
|
.unwrap()
|
|
63
|
-
}
|
|
64
|
-
None => {
|
|
65
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
66
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
67
|
-
Response::builder()
|
|
68
|
-
.status(StatusCode::OK)
|
|
69
|
-
.header("Content-Type", "text/html")
|
|
70
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
71
|
-
.unwrap()
|
|
72
|
-
} else {
|
|
73
|
-
Response::builder()
|
|
74
|
-
.status(StatusCode::NOT_FOUND)
|
|
75
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
76
|
-
.unwrap()
|
|
77
|
-
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -96,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
96
100
|
_ => "application/octet-stream",
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
103
|
+
}
|
|
@@ -82,8 +82,8 @@ fn copy_embedded_dir(dir: &Dir<'static>, dst: &str) -> Result<()> {
|
|
|
82
82
|
fs::create_dir_all(dst)?;
|
|
83
83
|
|
|
84
84
|
for entry in dir.entries() {
|
|
85
|
-
let
|
|
86
|
-
let name =
|
|
85
|
+
let entry_path = entry.path();
|
|
86
|
+
let name = entry_path.file_name().unwrap().to_str().unwrap();
|
|
87
87
|
let dst_path = format!("{}/{}", dst, name);
|
|
88
88
|
|
|
89
89
|
if let Some(subdir) = entry.as_dir() {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -16,7 +15,6 @@ path = "main.rs"
|
|
|
16
15
|
|
|
17
16
|
[dependencies]
|
|
18
17
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
19
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
20
18
|
anyhow = "1.0"
|
|
21
19
|
wry = "0.54"
|
|
22
20
|
tao = "0.34"
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#[cfg(not(debug_assertions))]
|
|
6
|
-
use include_dir::{include_dir, Dir};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
7
5
|
|
|
8
6
|
// Configuration'dan frontendDist path'ini oku
|
|
9
|
-
fn get_frontend_dist_path() ->
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
10
8
|
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
11
9
|
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
12
10
|
for line in config_content.lines() {
|
|
13
11
|
if line.trim().starts_with("frontendDist") {
|
|
14
|
-
if let Some(
|
|
15
|
-
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Varsayฤฑlan path
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#[cfg(not(debug_assertions))]
|
|
28
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
pub struct CustomProtocolHandler;
|
|
31
34
|
|
|
@@ -35,9 +38,11 @@ impl CustomProtocolHandler {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
38
43
|
#[cfg(debug_assertions)]
|
|
39
44
|
{
|
|
40
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
41
46
|
let _dist_path = get_frontend_dist_path();
|
|
42
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
43
48
|
return Response::builder()
|
|
@@ -49,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
49
54
|
|
|
50
55
|
#[cfg(not(debug_assertions))]
|
|
51
56
|
{
|
|
52
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
53
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
54
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
59
72
|
Response::builder()
|
|
60
73
|
.status(StatusCode::OK)
|
|
61
|
-
.header("Content-Type",
|
|
62
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
63
81
|
.unwrap()
|
|
64
|
-
}
|
|
65
|
-
None => {
|
|
66
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
67
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
68
|
-
Response::builder()
|
|
69
|
-
.status(StatusCode::OK)
|
|
70
|
-
.header("Content-Type", "text/html")
|
|
71
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
72
|
-
.unwrap()
|
|
73
|
-
} else {
|
|
74
|
-
Response::builder()
|
|
75
|
-
.status(StatusCode::NOT_FOUND)
|
|
76
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
77
|
-
.unwrap()
|
|
78
|
-
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -97,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
97
100
|
_ => "application/octet-stream",
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
103
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[[bin]]
|
|
@@ -9,7 +8,6 @@ name = "my-ionyx-app"
|
|
|
9
8
|
path = "main.rs"
|
|
10
9
|
|
|
11
10
|
[dependencies]
|
|
12
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
13
11
|
ionyx = "1.0.0"
|
|
14
12
|
anyhow = "1.0"
|
|
15
13
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -16,7 +15,6 @@ path = "main.rs"
|
|
|
16
15
|
|
|
17
16
|
[dependencies]
|
|
18
17
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
19
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
20
18
|
anyhow = "1.0"
|
|
21
19
|
wry = "0.54"
|
|
22
20
|
tao = "0.34"
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#[cfg(not(debug_assertions))]
|
|
6
|
-
use include_dir::{include_dir, Dir};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
7
5
|
|
|
8
6
|
// Configuration'dan frontendDist path'ini oku
|
|
9
|
-
fn get_frontend_dist_path() ->
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
10
8
|
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
11
9
|
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
12
10
|
for line in config_content.lines() {
|
|
13
11
|
if line.trim().starts_with("frontendDist") {
|
|
14
|
-
if let Some(
|
|
15
|
-
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Varsayฤฑlan path
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#[cfg(not(debug_assertions))]
|
|
28
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
pub struct CustomProtocolHandler;
|
|
31
34
|
|
|
@@ -35,9 +38,11 @@ impl CustomProtocolHandler {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
38
43
|
#[cfg(debug_assertions)]
|
|
39
44
|
{
|
|
40
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
41
46
|
let _dist_path = get_frontend_dist_path();
|
|
42
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
43
48
|
return Response::builder()
|
|
@@ -49,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
49
54
|
|
|
50
55
|
#[cfg(not(debug_assertions))]
|
|
51
56
|
{
|
|
52
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
53
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
54
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
59
72
|
Response::builder()
|
|
60
73
|
.status(StatusCode::OK)
|
|
61
|
-
.header("Content-Type",
|
|
62
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
63
81
|
.unwrap()
|
|
64
|
-
}
|
|
65
|
-
None => {
|
|
66
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
67
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
68
|
-
Response::builder()
|
|
69
|
-
.status(StatusCode::OK)
|
|
70
|
-
.header("Content-Type", "text/html")
|
|
71
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
72
|
-
.unwrap()
|
|
73
|
-
} else {
|
|
74
|
-
Response::builder()
|
|
75
|
-
.status(StatusCode::NOT_FOUND)
|
|
76
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
77
|
-
.unwrap()
|
|
78
|
-
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -97,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
97
100
|
_ => "application/octet-stream",
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
103
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -16,7 +15,6 @@ path = "main.rs"
|
|
|
16
15
|
|
|
17
16
|
[dependencies]
|
|
18
17
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
19
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
20
18
|
anyhow = "1.0"
|
|
21
19
|
wry = "0.54"
|
|
22
20
|
tao = "0.34"
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#[cfg(not(debug_assertions))]
|
|
6
|
-
use include_dir::{include_dir, Dir};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
7
5
|
|
|
8
6
|
// Configuration'dan frontendDist path'ini oku
|
|
9
|
-
fn get_frontend_dist_path() ->
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
10
8
|
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
11
9
|
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
12
10
|
for line in config_content.lines() {
|
|
13
11
|
if line.trim().starts_with("frontendDist") {
|
|
14
|
-
if let Some(
|
|
15
|
-
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Varsayฤฑlan path
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#[cfg(not(debug_assertions))]
|
|
28
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
pub struct CustomProtocolHandler;
|
|
31
34
|
|
|
@@ -35,9 +38,11 @@ impl CustomProtocolHandler {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
38
43
|
#[cfg(debug_assertions)]
|
|
39
44
|
{
|
|
40
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
41
46
|
let _dist_path = get_frontend_dist_path();
|
|
42
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
43
48
|
return Response::builder()
|
|
@@ -49,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
49
54
|
|
|
50
55
|
#[cfg(not(debug_assertions))]
|
|
51
56
|
{
|
|
52
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
53
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
54
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
59
72
|
Response::builder()
|
|
60
73
|
.status(StatusCode::OK)
|
|
61
|
-
.header("Content-Type",
|
|
62
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
63
81
|
.unwrap()
|
|
64
|
-
}
|
|
65
|
-
None => {
|
|
66
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
67
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
68
|
-
Response::builder()
|
|
69
|
-
.status(StatusCode::OK)
|
|
70
|
-
.header("Content-Type", "text/html")
|
|
71
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
72
|
-
.unwrap()
|
|
73
|
-
} else {
|
|
74
|
-
Response::builder()
|
|
75
|
-
.status(StatusCode::NOT_FOUND)
|
|
76
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
77
|
-
.unwrap()
|
|
78
|
-
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -97,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
97
100
|
_ => "application/octet-stream",
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
103
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
build = "build.rs"
|
|
3
2
|
name = "my-ionyx-app"
|
|
4
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
5
4
|
edition = "2021"
|
|
6
5
|
|
|
7
6
|
[workspace]
|
|
@@ -16,7 +15,6 @@ path = "main.rs"
|
|
|
16
15
|
|
|
17
16
|
[dependencies]
|
|
18
17
|
ionyx = { path = "../../../../../../src-ionyx" }
|
|
19
|
-
include_dir = { version = "0.7", features = ["glob"] }
|
|
20
18
|
anyhow = "1.0"
|
|
21
19
|
wry = "0.54"
|
|
22
20
|
tao = "0.34"
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
use std::borrow::Cow;
|
|
2
2
|
use wry::http::{Request, Response, StatusCode};
|
|
3
|
+
use std::path::{PathBuf};
|
|
4
|
+
use std::fs;
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
// Configuration'dan frontendDist path'ini oku
|
|
7
|
+
fn get_frontend_dist_path() -> PathBuf {
|
|
8
|
+
// รnce Ionyx config dosyasฤฑnฤฑ okumaya รงalฤฑล
|
|
9
|
+
if let Ok(config_content) = std::fs::read_to_string("ionyx.config.toml") {
|
|
10
|
+
for line in config_content.lines() {
|
|
11
|
+
if line.trim().starts_with("frontendDist") {
|
|
12
|
+
if let Some(path_str) = line.split('=').nth(1) {
|
|
13
|
+
let clean_path = path_str.trim().trim_matches('"');
|
|
14
|
+
return PathBuf::from(clean_path);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Varsayฤฑlan path: exe yanฤฑndaki dist klasรถrรผ
|
|
21
|
+
if let Ok(exe_path) = std::env::current_exe() {
|
|
22
|
+
if let Some(exe_dir) = exe_path.parent() {
|
|
23
|
+
let dist = exe_dir.join("dist");
|
|
24
|
+
if dist.exists() {
|
|
25
|
+
return dist;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
6
29
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#[cfg(not(debug_assertions))]
|
|
10
|
-
static EMBEDDED_ASSETS: Dir<'static> = include_dir!("../frontend/dist");
|
|
30
|
+
PathBuf::from("dist")
|
|
31
|
+
}
|
|
11
32
|
|
|
12
33
|
pub struct CustomProtocolHandler;
|
|
13
34
|
|
|
@@ -17,9 +38,12 @@ impl CustomProtocolHandler {
|
|
|
17
38
|
}
|
|
18
39
|
|
|
19
40
|
pub fn handle_request(&self, request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
|
|
41
|
+
let uri_path = request.uri().path();
|
|
42
|
+
|
|
20
43
|
#[cfg(debug_assertions)]
|
|
21
44
|
{
|
|
22
|
-
let _uri_path =
|
|
45
|
+
let _uri_path = uri_path;
|
|
46
|
+
let _dist_path = get_frontend_dist_path();
|
|
23
47
|
let _unused_ct = Self::get_content_type("index.html");
|
|
24
48
|
return Response::builder()
|
|
25
49
|
.status(StatusCode::NOT_FOUND)
|
|
@@ -30,33 +54,31 @@ impl CustomProtocolHandler {
|
|
|
30
54
|
|
|
31
55
|
#[cfg(not(debug_assertions))]
|
|
32
56
|
{
|
|
33
|
-
let
|
|
57
|
+
let dist_dir = get_frontend_dist_path();
|
|
34
58
|
let clean_path = uri_path.trim_start_matches('/');
|
|
35
59
|
let file_path = if clean_path.is_empty() { "index.html" } else { clean_path };
|
|
60
|
+
let full_path = dist_dir.join(file_path);
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
if let Ok(contents) = fs::read(&full_path) {
|
|
63
|
+
let content_type = Self::get_content_type(file_path);
|
|
64
|
+
Response::builder()
|
|
65
|
+
.status(StatusCode::OK)
|
|
66
|
+
.header("Content-Type", content_type)
|
|
67
|
+
.body(Cow::Owned(contents))
|
|
68
|
+
.unwrap()
|
|
69
|
+
} else {
|
|
70
|
+
let index_path = dist_dir.join("index.html");
|
|
71
|
+
if let Ok(index_contents) = fs::read(&index_path) {
|
|
40
72
|
Response::builder()
|
|
41
73
|
.status(StatusCode::OK)
|
|
42
|
-
.header("Content-Type",
|
|
43
|
-
.body(Cow::
|
|
74
|
+
.header("Content-Type", "text/html")
|
|
75
|
+
.body(Cow::Owned(index_contents))
|
|
76
|
+
.unwrap()
|
|
77
|
+
} else {
|
|
78
|
+
Response::builder()
|
|
79
|
+
.status(StatusCode::NOT_FOUND)
|
|
80
|
+
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
44
81
|
.unwrap()
|
|
45
|
-
}
|
|
46
|
-
None => {
|
|
47
|
-
// SPA (Single Page Application) desteฤi: Dosya bulunamazsa index.html'i dรถn
|
|
48
|
-
if let Some(index_file) = EMBEDDED_ASSETS.get_file("index.html") {
|
|
49
|
-
Response::builder()
|
|
50
|
-
.status(StatusCode::OK)
|
|
51
|
-
.header("Content-Type", "text/html")
|
|
52
|
-
.body(Cow::Borrowed::<'static, [u8]>(index_file.contents()))
|
|
53
|
-
.unwrap()
|
|
54
|
-
} else {
|
|
55
|
-
Response::builder()
|
|
56
|
-
.status(StatusCode::NOT_FOUND)
|
|
57
|
-
.body(Cow::Borrowed(&b"404 Not Found"[..]))
|
|
58
|
-
.unwrap()
|
|
59
|
-
}
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
84
|
}
|
|
@@ -78,5 +100,4 @@ impl CustomProtocolHandler {
|
|
|
78
100
|
_ => "application/octet-stream",
|
|
79
101
|
}
|
|
80
102
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::Path;
|
|
3
|
-
|
|
4
|
-
fn main() {
|
|
5
|
-
let dist_path = Path::new("../frontend/dist");
|
|
6
|
-
if !dist_path.exists() {
|
|
7
|
-
fs::create_dir_all(dist_path).unwrap();
|
|
8
|
-
fs::write(dist_path.join("index.html"), "<html><body><h1>Placeholder</h1></body></html>").unwrap();
|
|
9
|
-
}
|
|
10
|
-
println!("cargo:rerun-if-changed=../frontend/dist");
|
|
11
|
-
}
|