|
|
@ -1,9 +1,6 @@
|
|
|
|
use std::{
|
|
|
|
use std::{env, io, net::SocketAddrV4, sync::Arc};
|
|
|
|
env, io,
|
|
|
|
|
|
|
|
net::{SocketAddrV4},
|
|
|
|
|
|
|
|
sync::Arc,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use actix_cors::Cors;
|
|
|
|
use actix_identity::IdentityMiddleware;
|
|
|
|
use actix_identity::IdentityMiddleware;
|
|
|
|
use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware};
|
|
|
|
use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware};
|
|
|
|
use actix_web::{
|
|
|
|
use actix_web::{
|
|
|
@ -18,6 +15,7 @@ mod model;
|
|
|
|
use model::user::User;
|
|
|
|
use model::user::User;
|
|
|
|
// Define our repo module
|
|
|
|
// Define our repo module
|
|
|
|
mod repo;
|
|
|
|
mod repo;
|
|
|
|
|
|
|
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
|
|
|
use repo::todo_repository::TodoRepository;
|
|
|
|
use repo::todo_repository::TodoRepository;
|
|
|
|
use repo::user_repository::UserRepository;
|
|
|
|
use repo::user_repository::UserRepository;
|
|
|
|
// Define our routes module
|
|
|
|
// Define our routes module
|
|
|
@ -60,9 +58,24 @@ async fn main() -> io::Result<()> {
|
|
|
|
"{}:{}",
|
|
|
|
"{}:{}",
|
|
|
|
env::var("WEBSERVER_ADDRESS").unwrap_or(DEFAULT_WEBSERVER_ADDRESS.to_string()),
|
|
|
|
env::var("WEBSERVER_ADDRESS").unwrap_or(DEFAULT_WEBSERVER_ADDRESS.to_string()),
|
|
|
|
env::var("WEBSERVER_PORT").unwrap_or(DEFAULT_WEBSERVER_PORT.to_string())
|
|
|
|
env::var("WEBSERVER_PORT").unwrap_or(DEFAULT_WEBSERVER_PORT.to_string())
|
|
|
|
).parse().expect("A valid socket address. Check your ENV variables!");
|
|
|
|
)
|
|
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
|
|
.expect("A valid socket address. Check your ENV variables!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HOLY: Ich werde jetzt dann wirklich gleich verrückt mit CORS & Cookies...
|
|
|
|
|
|
|
|
// ICH WILL DOCH NUR DAS FRONTEND LOKAL TESTEN... IST DASS DENN ZU VIEL VERLANGT?
|
|
|
|
|
|
|
|
// TODO: Remove after local dev
|
|
|
|
|
|
|
|
// openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'
|
|
|
|
|
|
|
|
// Move to /cert/... in container
|
|
|
|
|
|
|
|
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;
|
|
|
|
|
|
|
|
builder.set_private_key_file("/cert/key.pem", SslFiletype::PEM)?;
|
|
|
|
|
|
|
|
builder.set_certificate_chain_file("/cert/cert.pem")?;
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("Starting HTTP server: http://{}:{}", socket_addr.ip(), socket_addr.port());
|
|
|
|
log::info!(
|
|
|
|
|
|
|
|
"Starting HTTP server: http://{}:{}",
|
|
|
|
|
|
|
|
socket_addr.ip(),
|
|
|
|
|
|
|
|
socket_addr.port()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
HttpServer::new(move || {
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
App::new()
|
|
|
@ -70,11 +83,21 @@ async fn main() -> io::Result<()> {
|
|
|
|
.wrap(IdentityMiddleware::default())
|
|
|
|
.wrap(IdentityMiddleware::default())
|
|
|
|
.wrap(
|
|
|
|
.wrap(
|
|
|
|
SessionMiddleware::builder(CookieSessionStore::default(), key.clone())
|
|
|
|
SessionMiddleware::builder(CookieSessionStore::default(), key.clone())
|
|
|
|
.cookie_secure(false)
|
|
|
|
.cookie_secure(true)
|
|
|
|
|
|
|
|
// TODO: Remove after development with local solidjs app
|
|
|
|
|
|
|
|
.cookie_same_site(actix_web::cookie::SameSite::None)
|
|
|
|
// Session lifetime
|
|
|
|
// Session lifetime
|
|
|
|
.session_lifecycle(PersistentSession::default().session_ttl(Duration::days(7)))
|
|
|
|
.session_lifecycle(PersistentSession::default().session_ttl(Duration::days(7)))
|
|
|
|
.build(),
|
|
|
|
.build(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
.wrap(
|
|
|
|
|
|
|
|
// TODO: Remove after development with local solidjs app
|
|
|
|
|
|
|
|
Cors::default()
|
|
|
|
|
|
|
|
.allowed_origin("http://localhost:3000")
|
|
|
|
|
|
|
|
.supports_credentials()
|
|
|
|
|
|
|
|
.allow_any_method()
|
|
|
|
|
|
|
|
.allow_any_header(),
|
|
|
|
|
|
|
|
)
|
|
|
|
.wrap(middleware::Logger::default())
|
|
|
|
.wrap(middleware::Logger::default())
|
|
|
|
.app_data(user_repo.clone())
|
|
|
|
.app_data(user_repo.clone())
|
|
|
|
.app_data(todo_repo.clone())
|
|
|
|
.app_data(todo_repo.clone())
|
|
|
@ -88,7 +111,7 @@ async fn main() -> io::Result<()> {
|
|
|
|
.service(routes::delete_logout)
|
|
|
|
.service(routes::delete_logout)
|
|
|
|
.default_service(web::to(routes::index))
|
|
|
|
.default_service(web::to(routes::index))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.bind(socket_addr)?
|
|
|
|
.bind_openssl(socket_addr, builder)?
|
|
|
|
.workers(2) // number of workers per bind default ist #cpus
|
|
|
|
.workers(2) // number of workers per bind default ist #cpus
|
|
|
|
.run()
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|