feat: minification #17

Merged
Anri merged 14 commits from minification into main 2023-04-09 19:30:04 +02:00
2 changed files with 72 additions and 27 deletions
Showing only changes of commit 7322bf0057 - Show all commits

31
run.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -o errexit # crash the script when a command crash
set -o pipefail # same as above for piped command
set -o nounset # crash when a variable doesnt exist
# TRACE=1 for debug
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
cd "$(dirname "$0")" # change script directory
main() {
dir_dist="./dist"
dir_template="/templates"
if [ ! -d "$dir_dist$dir_template" ]; then
echo "Copy template to dist directory"
mkdir -p "$dir_dist$dir_template"
cp -r ".$dir_template" "$dir_dist"
echo "Generate minified templates"
cargo run --release -- --no-http
fi
echo "Run the app"
cargo run --release
}
main "$@"

View file

@ -1,5 +1,6 @@
use actix_files::Files; use actix_files::Files;
use actix_web::{middleware::DefaultHeaders, web, App, HttpServer}; use actix_web::{middleware::DefaultHeaders, web, App, HttpServer};
use std::env;
use std::io; use std::io;
mod config; mod config;
@ -29,32 +30,45 @@ async fn main() -> io::Result<()> {
let addr = ("0.0.0.0", config.fc.port.unwrap()); let addr = ("0.0.0.0", config.fc.port.unwrap());
println!( let mut http = true;
"Listening to {}://{}:{}", let mut args = env::args();
config.clone().fc.scheme.unwrap(), args.next();
addr.0, for argument in args {
addr.1 if argument == "--no-http" {
); http = false
}
}
HttpServer::new(move || { if http {
App::new() println!(
.app_data(web::Data::new(config.clone())) "Listening to {}://{}:{}",
.wrap(DefaultHeaders::new().add(( config.clone().fc.scheme.unwrap(),
"Onion-Location", addr.0,
config.fc.onion.as_deref().unwrap_or_default(), addr.1
))) );
.service(index::page)
.service(agreements::security) HttpServer::new(move || {
.service(agreements::humans) App::new()
.service(agreements::robots) .app_data(web::Data::new(config.clone()))
.service(agreements::sitemap) .wrap(DefaultHeaders::new().add((
.service(networks::page) "Onion-Location",
.service(portfolio::page) config.fc.onion.as_deref().unwrap_or_default(),
.service(contrib::page) )))
.service(Files::new("/", config.static_location.clone())) .service(index::page)
.default_service(web::to(not_found::page)) .service(agreements::security)
}) .service(agreements::humans)
.bind(addr)? .service(agreements::robots)
.run() .service(agreements::sitemap)
.await .service(networks::page)
.service(portfolio::page)
.service(contrib::page)
.service(Files::new("/", config.static_location.clone()))
.default_service(web::to(not_found::page))
})
.bind(addr)?
.run()
.await
} else {
Ok(())
}
} }