parent
e1b0dec100
commit
6ebd48aeb6
2 changed files with 27 additions and 72 deletions
31
run.sh
31
run.sh
|
@ -1,31 +0,0 @@
|
||||||
#!/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 "$@"
|
|
68
src/main.rs
68
src/main.rs
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -30,45 +29,32 @@ 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());
|
||||||
|
|
||||||
let mut http = true;
|
println!(
|
||||||
let mut args = env::args();
|
"Listening to {}://{}:{}",
|
||||||
args.next();
|
config.clone().fc.scheme.unwrap(),
|
||||||
for argument in args {
|
addr.0,
|
||||||
if argument == "--no-http" {
|
addr.1
|
||||||
http = false
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if http {
|
HttpServer::new(move || {
|
||||||
println!(
|
App::new()
|
||||||
"Listening to {}://{}:{}",
|
.app_data(web::Data::new(config.clone()))
|
||||||
config.clone().fc.scheme.unwrap(),
|
.wrap(DefaultHeaders::new().add((
|
||||||
addr.0,
|
"Onion-Location",
|
||||||
addr.1
|
config.fc.onion.as_deref().unwrap_or_default(),
|
||||||
);
|
)))
|
||||||
|
.service(index::page)
|
||||||
HttpServer::new(move || {
|
.service(agreements::security)
|
||||||
App::new()
|
.service(agreements::humans)
|
||||||
.app_data(web::Data::new(config.clone()))
|
.service(agreements::robots)
|
||||||
.wrap(DefaultHeaders::new().add((
|
.service(agreements::sitemap)
|
||||||
"Onion-Location",
|
.service(networks::page)
|
||||||
config.fc.onion.as_deref().unwrap_or_default(),
|
.service(portfolio::page)
|
||||||
)))
|
.service(contrib::page)
|
||||||
.service(index::page)
|
.service(Files::new("/", config.static_location.clone()))
|
||||||
.service(agreements::security)
|
.default_service(web::to(not_found::page))
|
||||||
.service(agreements::humans)
|
})
|
||||||
.service(agreements::robots)
|
.bind(addr)?
|
||||||
.service(agreements::sitemap)
|
.run()
|
||||||
.service(networks::page)
|
.await
|
||||||
.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(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue