Skip to content

Commit

Permalink
Update main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
GPeaky committed Oct 16, 2024
1 parent 935e627 commit dd04cd8
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions crates/api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(portable_simd)]
mod config;
mod handlers;
mod middlewares;
Expand All @@ -18,44 +17,50 @@ use states::AppState;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[ntex::main]
#[tokio::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
initialize_tracing_subscriber();
let app_state = {
let db = Box::leak(Box::from(Database::new().await));
AppState::new(db).await.unwrap()
};

let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;

builder.set_private_key_file("certs/key.pem", SslFiletype::PEM)?;
builder.set_certificate_chain_file("certs/cert.pem")?;

// TODO - Make an recycle function to delete all unused data
let login_limit_visitors: &'static _ = Box::leak(Box::new(DashMap::with_capacity(1_000)));

web::server(move || {
web::App::new()
.configure(|svc| routes::api_routes(svc, login_limit_visitors))
.configure(routes::admin_routes)
.state(app_state.clone())
.wrap(
Cors::new()
.allowed_origin("https://intellitelemetry.live")
.allowed_origin("http://localhost:5173")
.allowed_methods(["GET", "POST", "DELETE"])
.allowed_headers([
header::ACCEPT,
header::CONTENT_TYPE,
header::AUTHORIZATION,
header::ACCESS_CONTROL_ALLOW_CREDENTIALS,
])
.max_age(3600)
.finish(),
)
})
.bind_openssl(var("HOST").unwrap(), builder)?
.run()
.await

ntex::rt::System::new("intelli-api")
.run_local(async {
let app_state = {
let db = Box::leak(Box::from(Database::new().await));
AppState::new(db).await.unwrap()
};

let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;

builder.set_private_key_file("certs/key.pem", SslFiletype::PEM)?;
builder.set_certificate_chain_file("certs/cert.pem")?;

// TODO - Make an recycle function to delete all unused data
let login_limit_visitors: &'static _ =
Box::leak(Box::new(DashMap::with_capacity(1_000)));

web::server(move || {
web::App::new()
.configure(|svc| routes::api_routes(svc, login_limit_visitors))
.configure(routes::admin_routes)
.state(app_state.clone())
.wrap(
Cors::new()
.allowed_origin("https://intellitelemetry.live")
.allowed_origin("http://localhost:5173")
.allowed_methods(["GET", "POST", "DELETE"])
.allowed_headers([
header::ACCEPT,
header::CONTENT_TYPE,
header::AUTHORIZATION,
header::ACCESS_CONTROL_ALLOW_CREDENTIALS,
])
.max_age(3600)
.finish(),
)
})
.bind_openssl(var("HOST").unwrap(), builder)?
.run()
.await
})
.await
}

0 comments on commit dd04cd8

Please sign in to comment.