Cleaned up directory, created documentation and readme

This commit is contained in:
Leonard Lorenz 2020-10-23 00:20:26 +02:00
parent 8a70db9b42
commit d6aee1e99d
16 changed files with 71 additions and 2 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
/target target
.env .env
html html
templates templates

4
README.md Normal file
View file

@ -0,0 +1,4 @@
# My website
Pure rust. Built with actix, diesel, tera, serde and sqlite3.
Environment variables are documented in [variables](./doc/environment.md)

7
doc/environment.md Normal file
View file

@ -0,0 +1,7 @@
# Environment Variables
- SUBMIT_TOKEN: Alphanumeric string to be used for creating blog posts
- ROOT_PATH: path where html, static and database reside
- SSL_PATH: path to SSL certificates containing key.pem and cert.pem
- BIND_PORT: port to bind to

View file

@ -727,6 +727,21 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]] [[package]]
name = "fuchsia-zircon" name = "fuchsia-zircon"
version = "0.3.3" version = "0.3.3"
@ -1284,6 +1299,33 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
dependencies = [
"bitflags",
"cfg-if 0.1.10",
"foreign-types",
"lazy_static",
"libc",
"openssl-sys",
]
[[package]]
name = "openssl-sys"
version = "0.9.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"
dependencies = [
"autocfg",
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.0" version = "0.11.0"
@ -1538,6 +1580,7 @@ dependencies = [
"chrono", "chrono",
"diesel 1.4.5", "diesel 1.4.5",
"diesel_codegen", "diesel_codegen",
"openssl",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",

View file

@ -21,3 +21,5 @@ diesel_codegen = { version = "*", default-features = false }
uuid = { version = "*", features = ["serde", "v5"] } uuid = { version = "*", features = ["serde", "v5"] }
tera = "*" tera = "*"
openssl = "*"

View file

@ -10,11 +10,24 @@ extern crate tera;
use actix_files as fs; use actix_files as fs;
use actix_web::{App, HttpServer}; use actix_web::{App, HttpServer};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(|| {
let root_path = config::get_from_env("ROOT_PATH", true); let root_path = config::get_from_env("ROOT_PATH", true);
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
builder
.set_private_key_file(
config::get_from_env("SSL_PATH", true) + "/key.pem",
SslFiletype::PEM,
)
.unwrap();
builder
.set_certificate_chain_file(config::get_from_env("SSL_PATH", true) + "/cert.pem")
.unwrap();
App::new() App::new()
//.wrap(middleware::NormalizePath::default()) //.wrap(middleware::NormalizePath::default())
.service(routes::root) .service(routes::root)
@ -24,7 +37,7 @@ async fn main() -> std::io::Result<()> {
.service(routes::blog_new_post) .service(routes::blog_new_post)
.service(fs::Files::new("/static", root_path + "/static")) .service(fs::Files::new("/static", root_path + "/static"))
}) })
.bind("localhost:8000")? .bind(String::from("localhost:") + &config::get_from_env("BIND_PORT", true))?
.run() .run()
.await .await
} }