Wrote foundation for proxy server handler
parent
0449af66d2
commit
5e4416f049
|
@ -52,6 +52,7 @@ incremental = true
|
|||
lto = "fat"
|
||||
incremental = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
# For releases also try to max optimizations for dependencies:
|
||||
[profile.release.build-override]
|
||||
|
|
7
Rb.yaml
7
Rb.yaml
|
@ -32,8 +32,9 @@ release:
|
|||
limits:
|
||||
forms: 32768
|
||||
|
||||
admin_user: "admin"
|
||||
admin_pass: "password"
|
||||
admin:
|
||||
username: "bever"
|
||||
password: "bever"
|
||||
jwt:
|
||||
key: "secret"
|
||||
refresh_token_size: 64
|
||||
|
@ -42,4 +43,4 @@ release:
|
|||
|
||||
databases:
|
||||
postgres_rb:
|
||||
url: "postgres://rb:rb@db:5432/rb"
|
||||
url: "postgres://rb:rb@localhost:5434/rb"
|
||||
|
|
|
@ -13,12 +13,14 @@ use rocket::{
|
|||
fairing::AdHoc,
|
||||
http::Status,
|
||||
serde::json::{json, Value},
|
||||
Build, Ignite, Request, Rocket,
|
||||
Build, Request, Rocket,
|
||||
};
|
||||
use rocket_sync_db_pools::database;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use proxy::ProxyServer;
|
||||
|
||||
pub mod v1;
|
||||
mod proxy;
|
||||
|
||||
#[database("postgres_rb")]
|
||||
pub struct RbDbConn(diesel::PgConnection);
|
||||
|
@ -104,7 +106,7 @@ fn rocket() -> _
|
|||
v1::auth::login,
|
||||
v1::auth::refresh_token,
|
||||
],
|
||||
);
|
||||
).mount("/v1/posts", ProxyServer::from("http://localhost:8000/v1/posts"));
|
||||
|
||||
// This let's the guards properly access the JWT credentials when needed
|
||||
let new_figment = rocket.figment();
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
use rocket::Route;
|
||||
use rocket::http::Method;
|
||||
use rocket::{Request, Data};
|
||||
use rocket::route::{Handler, Outcome};
|
||||
use rocket::response::Redirect;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProxyServer {
|
||||
root: String,
|
||||
rank: isize,
|
||||
}
|
||||
|
||||
impl ProxyServer {
|
||||
const DEFAULT_RANK: isize = 10;
|
||||
|
||||
pub fn new(root: String, rank: isize) -> Self {
|
||||
ProxyServer {
|
||||
root,
|
||||
rank,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from(root: &str) -> Self {
|
||||
Self::new(String::from(root), Self::DEFAULT_RANK)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<Route>> for ProxyServer {
|
||||
fn into(self) -> Vec<Route> {
|
||||
let mut routes: Vec<Route> = vec![];
|
||||
|
||||
static METHODS: [Method; 5] = [Method::Get, Method::Post, Method::Patch, Method::Delete, Method::Put];
|
||||
|
||||
for method in METHODS {
|
||||
let mut route = Route::ranked(self.rank, method, "/<path..>", self.clone());
|
||||
route.name = Some(format!("ProxyServer: {} {}", method.as_str(), self.root.clone()).into());
|
||||
|
||||
routes.push(route);
|
||||
}
|
||||
|
||||
routes
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl Handler for ProxyServer {
|
||||
async fn handle<'r>(&self, req: &'r Request<'_>, data: Data<'r>) -> Outcome<'r> {
|
||||
todo!()
|
||||
}
|
||||
}
|
Reference in New Issue