|
|
@ -1,6 +1,6 @@
|
|
|
|
use std::{env, io, net::SocketAddrV4, sync::Arc};
|
|
|
|
use std::{env, io, net::SocketAddrV4, sync::Arc};
|
|
|
|
|
|
|
|
|
|
|
|
use actix_cors::Cors;
|
|
|
|
// 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::{
|
|
|
@ -15,7 +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 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
|
|
|
@ -42,7 +42,7 @@ async fn main() -> io::Result<()> {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: web::Data is already an Arc
|
|
|
|
// TODO: web::Data is already an Arc
|
|
|
|
//-> Investigate if we really need the session as an Arc as well
|
|
|
|
//-> Investigate if we really need the session as an Arc as well
|
|
|
|
let user = User::new("admin", "init_pw_hash", "init_salt");
|
|
|
|
let user = User::new("admin", "nimda", "salzig");
|
|
|
|
let user_repo = web::Data::new(UserRepository::new(Arc::clone(&cassandra_session)));
|
|
|
|
let user_repo = web::Data::new(UserRepository::new(Arc::clone(&cassandra_session)));
|
|
|
|
if let Err(err) = user_repo.create(&user) {
|
|
|
|
if let Err(err) = user_repo.create(&user) {
|
|
|
|
log::debug!("Default user already exists: {err}");
|
|
|
|
log::debug!("Default user already exists: {err}");
|
|
|
@ -67,9 +67,9 @@ async fn main() -> io::Result<()> {
|
|
|
|
// TODO: Remove after local dev
|
|
|
|
// TODO: Remove after local dev
|
|
|
|
// openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'
|
|
|
|
// openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'
|
|
|
|
// Move to /cert/... in container
|
|
|
|
// Move to /cert/... in container
|
|
|
|
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;
|
|
|
|
// let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;
|
|
|
|
builder.set_private_key_file("/cert/key.pem", SslFiletype::PEM)?;
|
|
|
|
// builder.set_private_key_file("/cert/key.pem", SslFiletype::PEM)?;
|
|
|
|
builder.set_certificate_chain_file("/cert/cert.pem")?;
|
|
|
|
// builder.set_certificate_chain_file("/cert/cert.pem")?;
|
|
|
|
|
|
|
|
|
|
|
|
log::info!(
|
|
|
|
log::info!(
|
|
|
|
"Starting HTTP server: http://{}:{}",
|
|
|
|
"Starting HTTP server: http://{}:{}",
|
|
|
@ -83,21 +83,22 @@ 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(true)
|
|
|
|
.cookie_secure(false)
|
|
|
|
// TODO: Remove after development with local solidjs app
|
|
|
|
// TODO: Remove after development with local solidjs app
|
|
|
|
.cookie_same_site(actix_web::cookie::SameSite::None)
|
|
|
|
// .cookie_secure(true)
|
|
|
|
|
|
|
|
// .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
|
|
|
|
// TODO: Remove after development with local solidjs app
|
|
|
|
// .wrap(
|
|
|
|
Cors::default()
|
|
|
|
// Cors::default()
|
|
|
|
.allowed_origin("http://localhost:3000")
|
|
|
|
// .allowed_origin("http://localhost:3000")
|
|
|
|
.supports_credentials()
|
|
|
|
// .supports_credentials()
|
|
|
|
.allow_any_method()
|
|
|
|
// .allow_any_method()
|
|
|
|
.allow_any_header(),
|
|
|
|
// .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())
|
|
|
@ -111,7 +112,9 @@ 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_openssl(socket_addr, builder)?
|
|
|
|
.bind(socket_addr)?
|
|
|
|
|
|
|
|
// TODO: Remove after local dev
|
|
|
|
|
|
|
|
// .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
|
|
|
|