Skip to content

Commit 068785c

Browse files
committed
API backward compatibility for vmm and gw
1 parent 6803835 commit 068785c

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

gateway/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ async fn main() -> Result<()> {
175175
));
176176

177177
let mut rocket = rocket::custom(figment)
178-
.mount("/prpc", ra_rpc::prpc_routes!(Proxy, RpcHandler))
178+
.mount(
179+
"/prpc",
180+
ra_rpc::prpc_routes!(Proxy, RpcHandler, trim: "Tproxy."),
181+
)
179182
.attach(AdHoc::on_response("Add app version header", |_req, res| {
180183
Box::pin(async move {
181184
res.set_raw_header("X-App-Version", app_version());

ra-rpc/src/rocket_helper.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ fn query_field_get_bool(req: &Request<'_>, field_name: &str) -> bool {
6767
#[macro_export]
6868
macro_rules! prpc_routes {
6969
($state:ty, $handler:ty) => {{
70-
ra_rpc::declare_prpc_routes!(prpc_post, prpc_get, $state, $handler);
70+
$crate::prpc_routes!($state, $handler, trim: "")
71+
}};
72+
($state:ty, $handler:ty, trim: $trim_prefix:literal) => {{
73+
$crate::declare_prpc_routes!(prpc_post, prpc_get, $state, $handler, trim: $trim_prefix);
7174
rocket::routes![prpc_post, prpc_get]
7275
}};
7376
}
7477

7578
#[macro_export]
7679
macro_rules! declare_prpc_routes {
77-
($post:ident, $get:ident, $state:ty, $handler:ty) => {
78-
$crate::declare_prpc_routes!(path: "/<method>", $post, $get, $state, $handler);
80+
($post:ident, $get:ident, $state:ty, $handler:ty, trim: $trim_prefix:literal) => {
81+
$crate::declare_prpc_routes!(path: "/<method>", $post, $get, $state, $handler, trim: $trim_prefix);
7982
};
80-
(path: $path: literal, $post:ident, $get:ident, $state:ty, $handler:ty) => {
83+
(path: $path: literal, $post:ident, $get:ident, $state:ty, $handler:ty, trim: $trim_prefix:literal) => {
8184
#[rocket::post($path, data = "<data>")]
8285
async fn $post<'a: 'd, 'd>(
8386
state: &'a $crate::rocket_helper::deps::State<$state>,
@@ -90,6 +93,7 @@ macro_rules! declare_prpc_routes {
9093
.request(rpc_request)
9194
.method(method)
9295
.data(data)
96+
.method_trim_prefix($trim_prefix)
9397
.build()
9498
.handle::<$handler>()
9599
.await
@@ -105,6 +109,7 @@ macro_rules! declare_prpc_routes {
105109
.state(&**state)
106110
.request(rpc_request)
107111
.method(method)
112+
.method_trim_prefix($trim_prefix)
108113
.build()
109114
.handle::<$handler>()
110115
.await
@@ -184,6 +189,7 @@ pub struct PrpcHandler<'s, 'r, S> {
184189
state: &'s S,
185190
request: RpcRequest<'r>,
186191
method: &'r str,
192+
method_trim_prefix: Option<&'r str>,
187193
data: Option<Data<'r>>,
188194
}
189195

@@ -263,8 +269,10 @@ pub async fn handle_prpc_impl<S, Call: RpcCall<S>>(
263269
state,
264270
request,
265271
method,
272+
method_trim_prefix,
266273
data,
267274
} = args;
275+
let method = method.trim_start_matches(method_trim_prefix.unwrap_or_default());
268276
let remote_app_id = request
269277
.certificate
270278
.as_ref()

vmm/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async fn run_external_api(app: App, figment: Figment, api_auth: ApiToken) -> Res
4747
.mount("/", main_routes::routes())
4848
.mount("/guest", ra_rpc::prpc_routes!(App, GuestApiHandler))
4949
.mount("/api", ra_rpc::prpc_routes!(App, HostApiHandler))
50-
.mount("/prpc", ra_rpc::prpc_routes!(App, RpcHandler))
50+
.mount("/prpc", ra_rpc::prpc_routes!(App, RpcHandler, trim: "Teepod."))
5151
.manage(app)
5252
.manage(api_auth)
5353
.attach(AdHoc::on_response("Add app rev header", |_req, res| {

0 commit comments

Comments
 (0)