feat: get in the friends server
This commit is contained in:
parent
9f9393cfe5
commit
2417c109e4
9 changed files with 473 additions and 21 deletions
59
src/main.rs
59
src/main.rs
|
|
@ -1,15 +1,20 @@
|
|||
|
||||
|
||||
use std::env;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use dotenvy::dotenv;
|
||||
use juniper::{EmptyMutation, EmptySubscription};
|
||||
use log::info;
|
||||
use rocket::fairing::AdHoc;
|
||||
use rocket::futures::FutureExt;
|
||||
use rocket::http::Header;
|
||||
use rocket::routes;
|
||||
use sqlx::Postgres;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use tonic::transport::Server;
|
||||
use crate::graphql::{Query, Schema};
|
||||
|
||||
mod xml;
|
||||
mod conntest;
|
||||
|
|
@ -18,15 +23,49 @@ mod account;
|
|||
mod error;
|
||||
mod dsresponse;
|
||||
mod data_wrapper;
|
||||
#[deprecated]
|
||||
mod grpc;
|
||||
mod graphql;
|
||||
|
||||
type Pool = sqlx::Pool<Postgres>;
|
||||
|
||||
async fn start_grpc(){
|
||||
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");
|
||||
|
||||
let grpc_instance = grpc::AccountService(pool);
|
||||
|
||||
let addr: SocketAddr =
|
||||
SocketAddr::from((
|
||||
env::var("ROCKET_ADDRESS").ok()
|
||||
.map(|v| v.parse().expect("unable to read address"))
|
||||
.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
|
||||
7071
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
tokio::spawn(async move{
|
||||
Server::builder()
|
||||
.add_service(grpc::grpc::account_server::AccountServer::new(grpc_instance))
|
||||
.serve(addr)
|
||||
.await
|
||||
.expect("unable to start grpc server");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
#[rocket::launch]
|
||||
async fn launch() -> _ {
|
||||
dotenv().ok();
|
||||
|
||||
|
||||
start_grpc().await;
|
||||
|
||||
let act_database_url = env::var("DATABASE_URL").expect("account database url is not set");
|
||||
|
||||
|
|
@ -35,8 +74,19 @@ async fn launch() -> _ {
|
|||
.connect(&act_database_url).await
|
||||
.expect("unable to create pool");
|
||||
|
||||
let graph_pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&act_database_url).await
|
||||
.expect("unable to create pool");
|
||||
|
||||
rocket::build()
|
||||
.manage(pool)
|
||||
.manage(graphql::Context(graph_pool))
|
||||
.manage(Schema::new(
|
||||
Query,
|
||||
EmptyMutation::new(),
|
||||
EmptySubscription::new())
|
||||
)
|
||||
.attach(AdHoc::on_response("org", |_, response| Box::pin(async move {
|
||||
//response.adjoin_header(Header::new("x-organization", "Nintendo"));
|
||||
response.adjoin_header(Header::new("x-nintendo-date", SystemTime::now()
|
||||
|
|
@ -64,5 +114,12 @@ async fn launch() -> _ {
|
|||
nnid::people::get_own_profile,
|
||||
nnid::oauth::generate_token::generate_token,
|
||||
nnid::provider::get_nex_token,
|
||||
nnid::provider::get_service_token,
|
||||
nnid::mapped_ids::mapped_ids,
|
||||
//graphql
|
||||
graphql::graphiql,
|
||||
graphql::playground,
|
||||
graphql::get_graphql,
|
||||
graphql::post_graphql,
|
||||
])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue