Compare commits

...

2 Commits

Author SHA1 Message Date
realaravinth
cc1b48db27 cache buster version lock in 2021-04-13 22:59:39 +05:30
realaravinth
de6ceb1b3f broken route prefix 2021-04-12 19:03:55 +05:30
9 changed files with 330 additions and 90 deletions

216
Cargo.lock generated
View File

@@ -340,17 +340,41 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "aes"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7001367fde4c768a19d1029f0a8be5abd9308e1119846d5bd9ad26297b8faf5"
dependencies = [
"aes-soft 0.4.0",
"aesni 0.7.0",
"block-cipher",
]
[[package]] [[package]]
name = "aes" name = "aes"
version = "0.6.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561"
dependencies = [ dependencies = [
"aes-soft", "aes-soft 0.6.4",
"aesni", "aesni 0.10.0",
"cipher", "cipher",
] ]
[[package]]
name = "aes-gcm"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86f5007801316299f922a6198d1d09a0bae95786815d066d5880d13f7c45ead1"
dependencies = [
"aead",
"aes 0.4.0",
"block-cipher",
"ghash",
"subtle",
]
[[package]] [[package]]
name = "aes-gcm" name = "aes-gcm"
version = "0.8.0" version = "0.8.0"
@@ -358,13 +382,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da"
dependencies = [ dependencies = [
"aead", "aead",
"aes", "aes 0.6.0",
"cipher", "cipher",
"ctr", "ctr",
"ghash", "ghash",
"subtle", "subtle",
] ]
[[package]]
name = "aes-soft"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4925647ee64e5056cf231608957ce7c81e12d6d6e316b9ce1404778cc1d35fa7"
dependencies = [
"block-cipher",
"byteorder",
"opaque-debug 0.2.3",
]
[[package]] [[package]]
name = "aes-soft" name = "aes-soft"
version = "0.6.4" version = "0.6.4"
@@ -372,7 +407,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072"
dependencies = [ dependencies = [
"cipher", "cipher",
"opaque-debug", "opaque-debug 0.3.0",
]
[[package]]
name = "aesni"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050d39b0b7688b3a3254394c3e30a9d66c41dcf9b05b0e2dbdc623f6505d264"
dependencies = [
"block-cipher",
"opaque-debug 0.2.3",
] ]
[[package]] [[package]]
@@ -382,7 +427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce"
dependencies = [ dependencies = [
"cipher", "cipher",
"opaque-debug", "opaque-debug 0.3.0",
] ]
[[package]] [[package]]
@@ -580,6 +625,15 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "block-cipher"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa136449e765dc7faa244561ccae839c394048667929af599b5d931ebe7b7f10"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "brotli-sys" name = "brotli-sys"
version = "0.3.2" version = "0.3.2"
@@ -641,8 +695,8 @@ dependencies = [
[[package]] [[package]]
name = "cache-buster" name = "cache-buster"
version = "0.1.0" version = "0.1.1"
source = "git+https://github.com/realaravinth/cache-buster#71d5ef67a2788789922eaa484e10269acbaeb8a7" source = "git+https://github.com/realaravinth/cache-buster#d5593b2db677406b2c086d7eb25c9efb33d3b168"
dependencies = [ dependencies = [
"data-encoding", "data-encoding",
"derive_builder 0.10.0", "derive_builder 0.10.0",
@@ -694,6 +748,42 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chacha20"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "086c0f07ac275808b7bf9a39f2fd013aae1498be83632814c8c4e0bd53f2dc58"
dependencies = [
"stream-cipher",
"zeroize",
]
[[package]]
name = "chacha20poly1305"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18b0c90556d8e3fec7cf18d84a2f53d27b21288f2fe481b830fadcf809e48205"
dependencies = [
"aead",
"chacha20",
"poly1305",
"stream-cipher",
"zeroize",
]
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits 0.2.14",
"time 0.1.43",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "cipher" name = "cipher"
version = "0.2.5" version = "0.2.5"
@@ -743,10 +833,10 @@ version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951"
dependencies = [ dependencies = [
"aes-gcm", "aes-gcm 0.8.0",
"base64 0.13.0", "base64 0.13.0",
"hkdf", "hkdf",
"hmac", "hmac 0.10.1",
"percent-encoding", "percent-encoding",
"rand 0.8.3", "rand 0.8.3",
"sha2", "sha2",
@@ -802,9 +892,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.0" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"crossbeam-utils 0.8.3", "crossbeam-utils 0.8.3",
@@ -842,6 +932,16 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "crypto-mac"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
dependencies = [
"generic-array",
"subtle",
]
[[package]] [[package]]
name = "crypto-mac" name = "crypto-mac"
version = "0.10.0" version = "0.10.0"
@@ -852,6 +952,25 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "csrf"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1694fcc6e9386dbf87ad8c0a3ad3ab6d105eecc109afa4b4a5d126e7faf9b3bb"
dependencies = [
"aead",
"aes-gcm 0.6.0",
"byteorder",
"chacha20poly1305",
"chrono",
"data-encoding",
"generic-array",
"hmac 0.8.1",
"log",
"rand 0.7.3",
"sha2",
]
[[package]] [[package]]
name = "ctr" name = "ctr"
version = "0.6.0" version = "0.6.0"
@@ -1284,7 +1403,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375"
dependencies = [ dependencies = [
"opaque-debug", "opaque-debug 0.3.0",
"polyval", "polyval",
] ]
@@ -1297,10 +1416,12 @@ dependencies = [
"actix-http", "actix-http",
"actix-identity", "actix-identity",
"actix-rt", "actix-rt",
"actix-service",
"actix-web", "actix-web",
"argon2-creds", "argon2-creds",
"cache-buster", "cache-buster",
"config", "config",
"csrf",
"derive_builder 0.10.0", "derive_builder 0.10.0",
"derive_more", "derive_more",
"futures", "futures",
@@ -1392,7 +1513,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
dependencies = [ dependencies = [
"digest", "digest",
"hmac", "hmac 0.10.1",
]
[[package]]
name = "hmac"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840"
dependencies = [
"crypto-mac 0.8.0",
"digest",
] ]
[[package]] [[package]]
@@ -1401,7 +1532,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [ dependencies = [
"crypto-mac", "crypto-mac 0.10.0",
"digest", "digest",
] ]
@@ -1706,7 +1837,7 @@ checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"digest", "digest",
"opaque-debug", "opaque-debug 0.3.0",
] ]
[[package]] [[package]]
@@ -1824,6 +1955,16 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits 0.2.14",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.1.43" version = "0.1.43"
@@ -1858,6 +1999,12 @@ version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
version = "0.3.0" version = "0.3.0"
@@ -2000,6 +2147,16 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "poly1305"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b7456bc1ad2d4cf82b3a016be4c2ac48daf11bf990c1603ebd447fe6f30fca8"
dependencies = [
"cpuid-bool 0.2.0",
"universal-hash",
]
[[package]] [[package]]
name = "polyval" name = "polyval"
version = "0.4.5" version = "0.4.5"
@@ -2007,7 +2164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd"
dependencies = [ dependencies = [
"cpuid-bool 0.2.0", "cpuid-bool 0.2.0",
"opaque-debug", "opaque-debug 0.3.0",
"universal-hash", "universal-hash",
] ]
@@ -2385,9 +2542,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "sct" name = "sct"
version = "0.6.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce"
dependencies = [ dependencies = [
"ring", "ring",
"untrusted", "untrusted",
@@ -2510,7 +2667,7 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpuid-bool 0.1.2", "cpuid-bool 0.1.2",
"digest", "digest",
"opaque-debug", "opaque-debug 0.3.0",
] ]
[[package]] [[package]]
@@ -2529,7 +2686,7 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpuid-bool 0.1.2", "cpuid-bool 0.1.2",
"digest", "digest",
"opaque-debug", "opaque-debug 0.3.0",
] ]
[[package]] [[package]]
@@ -2612,7 +2769,7 @@ dependencies = [
"byteorder", "byteorder",
"bytes 0.5.6", "bytes 0.5.6",
"crc", "crc",
"crossbeam-channel 0.5.0", "crossbeam-channel 0.5.1",
"crossbeam-queue", "crossbeam-queue",
"crossbeam-utils 0.8.3", "crossbeam-utils 0.8.3",
"either", "either",
@@ -2621,7 +2778,7 @@ dependencies = [
"futures-util", "futures-util",
"hashlink", "hashlink",
"hex", "hex",
"hmac", "hmac 0.10.1",
"itoa", "itoa",
"libc", "libc",
"log", "log",
@@ -2743,6 +2900,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "stream-cipher"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09f8ed9974042b8c3672ff3030a69fcc03b74c47c3d1ecb7755e8a3626011e88"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.8.1" version = "0.8.1"
@@ -3411,3 +3577,9 @@ checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [ dependencies = [
"linked-hash-map", "linked-hash-map",
] ]
[[package]]
name = "zeroize"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81a974bcdd357f0dca4d41677db03436324d45a4c9ed2d0b873a5a360ce41c36"

View File

@@ -28,11 +28,13 @@ actix-identity = "0.3"
actix-http = "2.2" actix-http = "2.2"
actix-rt = "1" actix-rt = "1"
actix-cors = "0.5.4" actix-cors = "0.5.4"
actix-service = "1.0.6"
csrf = "0.4.0"
mime_guess = "2.0.3" mime_guess = "2.0.3"
rust-embed = "5.9.0" rust-embed = "5.9.0"
cache-buster = { version = "0.1", git = "https://github.com/realaravinth/cache-buster" } cache-buster = { version = "0.1.0", git = "https://github.com/realaravinth/cache-buster" }
futures = "0.3.14" futures = "0.3.14"
@@ -66,10 +68,14 @@ sailfish = "0.3.2"
[build-dependencies] [build-dependencies]
serde_yaml = "0.8.17" serde_yaml = "0.8.17"
serde = "1"
serde_json = "1" serde_json = "1"
yaml-rust = "0.4.5" yaml-rust = "0.4.5"
cache-buster = { version = "0.1", git = "https://github.com/realaravinth/cache-buster" } cache-buster = { version = "0.1.0", git = "https://github.com/realaravinth/cache-buster" }
mime = "0.3.16" mime = "0.3.16"
log = "0.4"
config = "0.11"
url = "2.2"
[dev-dependencies] [dev-dependencies]
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" } pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }

View File

@@ -15,9 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use cache_buster::BusterBuilder;
use std::process::Command; use std::process::Command;
use cache_buster::BusterBuilder;
#[path = "./src/settings.rs"]
mod settings;
fn main() { fn main() {
// note: add error checking yourself. // note: add error checking yourself.
let output = Command::new("git") let output = Command::new("git")
@@ -37,6 +41,7 @@ fn main() {
} }
fn cache_bust() { fn cache_bust() {
let settings = settings::Settings::new().unwrap();
let types = vec![ let types = vec![
mime::IMAGE_PNG, mime::IMAGE_PNG,
mime::IMAGE_SVG, mime::IMAGE_SVG,
@@ -49,11 +54,12 @@ fn cache_bust() {
let config = BusterBuilder::default() let config = BusterBuilder::default()
.source("./static") .source("./static")
.result("./prod") .result("./prod")
.prefix(settings.server.url_prefix)
.mime_types(types) .mime_types(types)
.copy(true) .copy(true)
.follow_links(true) .follow_links(true)
.build() .build()
.unwrap(); .unwrap();
config.process().unwrap().to_env(); config.process().unwrap();
} }

View File

@@ -28,7 +28,7 @@ ip= "0.0.0.0"
# enter your hostname, eg: example.com # enter your hostname, eg: example.com
domain = "localhost" domain = "localhost"
allow_registration = true allow_registration = true
#url_prefix = "" url_prefix = "/test"
[pow] [pow]
# Please set a unique value, your mCaptcha instance's security depends on this being # Please set a unique value, your mCaptcha instance's security depends on this being

View File

@@ -39,7 +39,7 @@
window.onload = function() { window.onload = function() {
// Begin Swagger UI call region // Begin Swagger UI call region
const ui = SwaggerUIBundle({ const ui = SwaggerUIBundle({
url: "/docs/openapi.json", url: "./openapi.json",
dom_id: '#swagger-ui', dom_id: '#swagger-ui',
deepLinking: true, deepLinking: true,
presets: [ presets: [

View File

@@ -15,19 +15,22 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::borrow::Cow;
use actix_web::body::Body; use actix_web::body::Body;
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use mime_guess::from_path; use mime_guess::from_path;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
use std::borrow::Cow; use crate::SETTINGS;
#[derive(RustEmbed)] #[derive(RustEmbed)]
#[folder = "docs/"] #[folder = "docs/"]
struct Asset; struct Asset;
pub fn handle_embedded_file(path: &str) -> HttpResponse { pub fn handle_embedded_file(path: &str) -> HttpResponse {
match Asset::get(path) { println!("{}", &path);
match Asset::get(&path) {
Some(content) => { Some(content) => {
let body: Body = match content { let body: Body = match content {
Cow::Borrowed(bytes) => bytes.into(), Cow::Borrowed(bytes) => bytes.into(),
@@ -55,6 +58,7 @@ async fn spec() -> HttpResponse {
#[get("/docs")] #[get("/docs")]
async fn index() -> HttpResponse { async fn index() -> HttpResponse {
println!("checking index");
handle_embedded_file("index.html") handle_embedded_file("index.html")
} }

View File

@@ -16,11 +16,10 @@
*/ */
use std::env; use std::env;
use actix_cors::Cors;
use actix_identity::{CookieIdentityPolicy, IdentityService}; use actix_identity::{CookieIdentityPolicy, IdentityService};
use actix_web::{ use actix_web::{
client::Client, error::InternalError, http::StatusCode, middleware, web::scope, error::InternalError, http::StatusCode, middleware, web::scope, web::JsonConfig, App,
web::JsonConfig, App, HttpServer, HttpServer,
}; };
//use awc::Client; //use awc::Client;
use cache_buster::Files as FileMap; use cache_buster::Files as FileMap;
@@ -49,8 +48,8 @@ lazy_static! {
// pub static ref OPEN_API_DOC: String = env::var("OPEN_API_DOCS").unwrap(); // pub static ref OPEN_API_DOC: String = env::var("OPEN_API_DOCS").unwrap();
pub static ref S: String = env::var("S").unwrap(); pub static ref S: String = env::var("S").unwrap();
pub static ref FILES: FileMap = FileMap::load(); pub static ref FILES: FileMap = FileMap::new();
pub static ref JS: &'static str = FILES.get("./static/bundle/main.js").unwrap(); pub static ref JS: &'static str = FILES.get_full_path("./static/bundle/main.js").unwrap();
pub static ref CSS: &'static str = FILES.get("./static/bundle/main.css").unwrap(); pub static ref CSS: &'static str = FILES.get("./static/bundle/main.css").unwrap();
} }
@@ -67,8 +66,6 @@ pub static VERIFICATION_PATH: &str = "mcaptchaVerificationChallenge.json";
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
use api::v1;
use docs;
pretty_env_logger::init(); pretty_env_logger::init();
info!( info!(
"{}: {}.\nFor more information, see: {}\nBuild info:\nVersion: {} commit: {}", "{}: {}.\nFor more information, see: {}\nBuild info:\nVersion: {} commit: {}",
@@ -79,36 +76,36 @@ async fn main() -> std::io::Result<()> {
sqlx::migrate!("./migrations/").run(&data.db).await.unwrap(); sqlx::migrate!("./migrations/").run(&data.db).await.unwrap();
HttpServer::new(move || { HttpServer::new(move || {
let client = Client::default(); // let mut app = App::new()
// .wrap(middleware::Logger::default())
// let captcha_api_cors = Cors::default() // .wrap(get_identity_service())
// .allow_any_origin() // .wrap(middleware::Compress::default())
// .allowed_methods(vec!["POST"]) // .data(data.clone())
// .allow_any_header() // .data(client.clone())
// .max_age(0) // .wrap(middleware::NormalizePath::new(
// .send_wildcard(); // middleware::normalize::TrailingSlash::Trim,
// ))
App::new() // .app_data(get_json_err());
.wrap(middleware::Logger::default()) //
.wrap(get_identity_service()) // if let Some(prefix) = &SETTINGS.server.url_prefix {
.wrap(middleware::Compress::default()) // app = app.service(
.data(data.clone()) // scope(prefix)
.data(client.clone()) // .configure(v1::pow::services)
.wrap(middleware::NormalizePath::new( // .configure(v1::services)
middleware::normalize::TrailingSlash::Trim, // .configure(docs::services)
)) // .configure(templates::services)
.configure(v1::pow::services) // .configure(static_assets::services),
.configure(v1::services) // );
//.service( // } else {
// scope("/") // app = app
// .wrap(captcha_api_cors) // .configure(v1::pow::services)
// .configure(v1::pow::services), // .configure(v1::services)
//) // .configure(docs::services)
.configure(docs::services) // .configure(templates::services)
.configure(templates::services) // .configure(static_assets::services);
.configure(static_assets::services) // }
.app_data(get_json_err()) let app = get_scoped_app!(data);
// .service(Files::new("/", "./prod")) app
}) })
.bind(SETTINGS.server.get_ip()) .bind(SETTINGS.server.get_ip())
.unwrap() .unwrap()
@@ -136,3 +133,45 @@ pub fn get_identity_service() -> IdentityService<CookieIdentityPolicy> {
.secure(false), .secure(false),
) )
} }
#[macro_export]
macro_rules! get_scoped_app {
($data:expr) => {
App::new()
.wrap(middleware::Logger::default())
.wrap(get_identity_service())
.wrap(middleware::Compress::default())
.data($data.clone())
.wrap(middleware::NormalizePath::new(
middleware::normalize::TrailingSlash::Trim,
))
.app_data(get_json_err())
.service(
scope(&crate::SETTINGS.server.url_prefix)
.configure(crate::api::v1::pow::services)
.configure(crate::api::v1::services)
.configure(crate::docs::services)
.configure(crate::templates::services)
.configure(crate::static_assets::services),
)
// if let Some(prefix) = &SETTINGS.server.url_prefix {
// app = app.service(
// scope(prefix)
// .configure(crate::api::v1::pow::services)
// .configure(crate::api::v1::services)
// .configure(crate::docs::services)
// .configure(crate::templates::services)
// .configure(crate::static_assets::services),
// );
// } else {
// app = app
//.configure(crate::api::v1::pow::services)
// .configure(crate::api::v1::services)
// .configure(crate::docs::services)
// .configure(crate::templates::services)
// .configure(crate::static_assets::services),
// }
// app
};
}

View File

@@ -17,7 +17,7 @@
use std::env; use std::env;
use config::{Config, ConfigError, Environment, File}; use config::{Config, ConfigError, Environment, File};
use log::debug; use log::{debug, info};
use serde::Deserialize; use serde::Deserialize;
use url::Url; use url::Url;
@@ -29,7 +29,7 @@ pub struct Server {
pub domain: String, pub domain: String,
pub cookie_secret: String, pub cookie_secret: String,
pub ip: String, pub ip: String,
pub url_prefix: Option<String>, pub url_prefix: String,
} }
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
@@ -44,13 +44,18 @@ impl Server {
format!("{}:{}", self.ip, self.port) format!("{}:{}", self.ip, self.port)
} }
fn check_url_prefix(&mut self) { fn check_url_prefix(prefix: Option<String>) -> String {
if let Some(prefix) = self.url_prefix.clone() { let mut url_prefix;
self.url_prefix = Some(prefix.trim().into()); if let Some(prefix) = prefix.clone() {
url_prefix = prefix.trim().into();
if prefix.trim().is_empty() { if prefix.trim().is_empty() {
self.url_prefix = None; url_prefix = "".into();
} }
} else {
url_prefix = "".into();
} }
url_prefix
} }
} }
@@ -133,11 +138,34 @@ impl Settings {
} }
set_database_url(&mut s); set_database_url(&mut s);
set_url_prefix(&mut s);
s.try_into() s.try_into()
} }
} }
#[cfg(not(tarpaulin_include))]
fn set_url_prefix(s: &mut Config) {
let prefix = s
.get::<Option<String>>("server.url_prefix")
.expect("Couldn't access server url prefix");
let mut url_prefix: String;
if let Some(prefix) = prefix.clone() {
url_prefix = prefix.trim().into();
if prefix.trim().is_empty() {
url_prefix = "".into();
}
} else {
url_prefix = "".into();
}
info!("Setting URL prefix to: {}", &url_prefix);
s.set("server.url_prefix", url_prefix)
.expect("Couldn't set url prefix");
}
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) { fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) {
s.set("database.username", database_conf.username.clone()) s.set("database.username", database_conf.username.clone())
@@ -172,19 +200,3 @@ fn set_database_url(s: &mut Config) {
) )
.expect("Couldn't set databse url"); .expect("Couldn't set databse url");
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn url_prefix_test() {
let mut settings = Settings::new().unwrap();
assert!(settings.server.url_prefix.is_none());
settings.server.url_prefix = Some("test".into());
settings.server.check_url_prefix();
settings.server.url_prefix = Some(" ".into());
settings.server.check_url_prefix();
assert!(settings.server.url_prefix.is_none());
}
}

View File

@@ -1,4 +1,5 @@
</body> </body>
<link rel="stylesheet" href="<.= &*crate::CSS .>" type="text/css" media="all"> <link rel="stylesheet" href="<.= &*crate::CSS .>" type="text/css" media="all">
<. println!("{}", &*crate::JS); .>
<script src="<.= &*crate::JS .>"></script> <script src="<.= &*crate::JS .>"></script>
</html> </html>