account/src/main.rs

68 lines
2 KiB
Rust
Raw Normal View History

2025-03-05 20:28:25 +01:00
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;
2025-02-27 21:49:37 +01:00
mod data_wrapper;
mod grpc;
2025-02-27 10:25:31 +01:00
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()
));
2025-02-27 21:49:37 +01:00
//response.adjoin_header(Header::new("Content-Type", "text/xml; charset=utf-8"));
2025-02-27 10:25:31 +01:00
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,
2025-02-27 21:49:37 +01:00
nnid::email::validate,
2025-03-05 20:28:25 +01:00
nnid::people::create_account,
nnid::people::get_own_profile,
nnid::oauth::generate_token::generate_token,
nnid::provider::get_nex_token,
2025-02-27 10:25:31 +01:00
])
2025-02-23 19:33:55 +01:00
}