add script
This commit is contained in:
parent
d1568f406d
commit
7322bf0057
2 changed files with 72 additions and 27 deletions
31
run.sh
Executable file
31
run.sh
Executable 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 "$@"
|
14
src/main.rs
14
src/main.rs
|
@ -1,5 +1,6 @@
|
|||
use actix_files::Files;
|
||||
use actix_web::{middleware::DefaultHeaders, web, App, HttpServer};
|
||||
use std::env;
|
||||
use std::io;
|
||||
|
||||
mod config;
|
||||
|
@ -29,6 +30,16 @@ async fn main() -> io::Result<()> {
|
|||
|
||||
let addr = ("0.0.0.0", config.fc.port.unwrap());
|
||||
|
||||
let mut http = true;
|
||||
let mut args = env::args();
|
||||
args.next();
|
||||
for argument in args {
|
||||
if argument == "--no-http" {
|
||||
http = false
|
||||
}
|
||||
}
|
||||
|
||||
if http {
|
||||
println!(
|
||||
"Listening to {}://{}:{}",
|
||||
config.clone().fc.scheme.unwrap(),
|
||||
|
@ -57,4 +68,7 @@ async fn main() -> io::Result<()> {
|
|||
.bind(addr)?
|
||||
.run()
|
||||
.await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue