account/src/main.rs

60 lines
1.8 KiB
Rust
Raw Normal View History

2025-02-24 10:43:47 +01:00
use std::env;
2025-02-27 10:25:31 +01:00
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
2025-02-24 10:43:47 +01:00
use dotenvy::dotenv;
2025-02-27 10:25:31 +01:00
use log::info;
2025-02-24 10:43:47 +01:00
use rocket::fairing::AdHoc;
use rocket::http::Header;
2025-02-23 19:33:55 +01:00
use rocket::routes;
2025-02-27 10:25:31 +01:00
use sqlx::Postgres;
use sqlx::postgres::PgPoolOptions;
2025-02-23 19:33:55 +01:00
mod xml;
mod conntest;
2025-02-27 10:25:31 +01:00
mod nnid;
2025-02-24 10:43:47 +01:00
mod account;
2025-02-27 10:25:31 +01:00
mod error;
mod dsresponse;
type Pool = sqlx::Pool<Postgres>;
2025-02-23 19:33:55 +01:00
#[rocket::launch]
async fn launch() -> _ {
2025-02-24 10:43:47 +01:00
dotenv().ok();
2025-02-27 10:25:31 +01:00
let act_database_url = env::var("DATABASE_URL").expect("account database url is not set");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&act_database_url).await
.expect("unable to create pool");
2025-02-24 10:43:47 +01:00
2025-02-23 19:33:55 +01:00
rocket::build()
2025-02-27 10:25:31 +01:00
.manage(pool)
2025-02-24 10:43:47 +01:00
.attach(AdHoc::on_response("org", |_, response| Box::pin(async move {
2025-02-27 10:25:31 +01:00
//response.adjoin_header(Header::new("x-organization", "Nintendo"));
response.adjoin_header(Header::new("x-nintendo-date", SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis()
.to_string()
));
response.adjoin_header(Header::new("Content-Type", "text/xml; charset=utf-8"));
response.remove_header("x-content-type-options");
response.remove_header("x-frame-options");
response.remove_header("permissions-policy");
2025-02-24 10:43:47 +01:00
})))
2025-02-27 10:25:31 +01:00
.mount("/", routes![
conntest::conntest,
nnid::devices::current_device_status,
nnid::agreements::get_agreement,
nnid::timezones::get_timezone,
nnid::person_exists::person_exists,
nnid::email::validate
])
2025-02-23 19:33:55 +01:00
}