build: WIP! include static files into binary

This commit is contained in:
Max Hohlfeld 2024-07-10 17:46:57 +02:00
parent 95c0324098
commit f13ce43145
7 changed files with 128 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
*.db*
/static_packages/node_modules

56
Cargo.lock generated
View File

@ -237,6 +237,18 @@ dependencies = [
"syn 2.0.57",
]
[[package]]
name = "actix-web-static-files"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf6d1ef6d7a60e084f9e0595e2a5234abda14e76c105ecf8e2d0e8800c41a1f"
dependencies = [
"actix-web",
"derive_more",
"futures-util",
"static-files",
]
[[package]]
name = "addr2line"
version = "0.21.0"
@ -748,6 +760,7 @@ dependencies = [
"actix-identity",
"actix-session",
"actix-web",
"actix-web-static-files",
"anyhow",
"argon2",
"askama",
@ -763,6 +776,7 @@ dependencies = [
"serde",
"serde_json",
"sqlx",
"static-files",
]
[[package]]
@ -829,6 +843,16 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "change-detection"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "159fa412eae48a1d94d0b9ecdb85c97ce56eb2a347c62394d3fdbf221adabc1a"
dependencies = [
"path-matchers",
"path-slash",
]
[[package]]
name = "chrono"
version = "0.4.37"
@ -1362,6 +1386,12 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gloo-timers"
version = "0.2.6"
@ -1975,6 +2005,21 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "path-matchers"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36cd9b72a47679ec193a5f0229d9ab686b7bd45e1fbc59ccf953c9f3d83f7b2b"
dependencies = [
"glob",
]
[[package]]
name = "path-slash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498a099351efa4becc6a19c72aa9270598e8fd274ca47052e37455241c88b696"
[[package]]
name = "percent-encoding"
version = "2.3.1"
@ -2592,6 +2637,17 @@ dependencies = [
"winapi",
]
[[package]]
name = "static-files"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e8590e848e1c53be9258210bcd4a8f4118e08988f03a4e2d63b62e4ad9f7ced"
dependencies = [
"change-detection",
"mime_guess",
"path-slash",
]
[[package]]
name = "stringprep"
version = "0.1.4"

View File

@ -25,3 +25,8 @@ rand = { version = "0.8.5", features = ["getrandom"] }
async-trait = "0.1.79"
lettre = "0.11.7"
quick-xml = { version = "0.31.0", features = ["serde", "serialize"] }
actix-web-static-files = "4.0"
static-files = "0.2.1"
[build-dependencies]
static-files = "0.2.1"

13
build.rs Normal file
View File

@ -0,0 +1,13 @@
use static_files::NpmBuild;
use std::path::Path;
fn main() -> std::io::Result<()> {
NpmBuild::new("./static_packages")
.install()?
.change_detection()
.to_resource_dir()
.with_filter(|x: &Path| x.ends_with("feather-sprite.svg"))
.build()?;
Ok(())
}

View File

@ -7,6 +7,7 @@ use actix_identity::IdentityMiddleware;
use actix_session::SessionMiddleware;
use actix_web::cookie::Key;
use actix_web::{web, App, HttpServer};
use actix_web_static_files::ResourceFiles;
use dotenv::dotenv;
use sqlx::postgres::PgPool;
@ -22,6 +23,7 @@ mod middleware;
mod filters;
mod postgres_session_store;
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
pub enum Command {
Migrate,
@ -115,6 +117,8 @@ async fn main() -> anyhow::Result<()> {
println!("Starting server on http://localhost:8080.");
HttpServer::new(move || {
let generated = generate();
App::new()
.app_data(web::Data::new(pool.clone()))
.configure(endpoints::init)
@ -126,7 +130,8 @@ async fn main() -> anyhow::Result<()> {
.build(),
)
.wrap(SessionMiddleware::new(store.clone(), secret_key.clone()))
.service(actix_files::Files::new("/static", "./static").show_files_listing())
//.service(actix_files::Files::new("/static", "./static").show_files_listing())
.service(ResourceFiles::new("/static", generated))
})
.bind(("127.0.0.1", 8080))?
.run()

42
static_packages/package-lock.json generated Normal file
View File

@ -0,0 +1,42 @@
{
"name": "static_packages",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"devDependencies": {
"feather-icons": "^4.29.2"
}
},
"node_modules/classnames": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
"integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==",
"dev": true,
"license": "MIT"
},
"node_modules/core-js": {
"version": "3.37.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.37.1.tgz",
"integrity": "sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/feather-icons": {
"version": "4.29.2",
"resolved": "https://registry.npmjs.org/feather-icons/-/feather-icons-4.29.2.tgz",
"integrity": "sha512-0TaCFTnBTVCz6U+baY2UJNKne5ifGh7sMG4ZC2LoBWCZdIyPa+y6UiR4lEYGws1JOFWdee8KAsAIvu0VcXqiqA==",
"dev": true,
"license": "MIT",
"dependencies": {
"classnames": "^2.2.5",
"core-js": "^3.1.3"
}
}
}
}

View File

@ -0,0 +1,5 @@
{
"devDependencies": {
"feather-icons": "^4.29.2"
}
}