mirror of
https://github.com/actix/examples
synced 2025-01-23 06:14:35 +01:00
Merge pull request #280 from Jonathas-Conceicao/topic/fix_jsonrpc
jsonrpc: Fix AppState extraction
This commit is contained in:
commit
20123c5d80
@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use actix_rt::time::delay_for;
|
use actix_rt::time::delay_for;
|
||||||
use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::{Future, FutureExt};
|
use futures::{Future, FutureExt};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
@ -14,7 +14,10 @@ use serde_json::Value;
|
|||||||
mod convention;
|
mod convention;
|
||||||
|
|
||||||
/// The main handler for JSONRPC server.
|
/// The main handler for JSONRPC server.
|
||||||
async fn rpc_handler(req: HttpRequest, body: Bytes) -> Result<HttpResponse, Error> {
|
async fn rpc_handler(
|
||||||
|
body: Bytes,
|
||||||
|
app_state: web::Data<AppState>,
|
||||||
|
) -> Result<HttpResponse, Error> {
|
||||||
let reqjson: convention::Request = match serde_json::from_slice(body.as_ref()) {
|
let reqjson: convention::Request = match serde_json::from_slice(body.as_ref()) {
|
||||||
Ok(ok) => ok,
|
Ok(ok) => ok,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -29,7 +32,6 @@ async fn rpc_handler(req: HttpRequest, body: Bytes) -> Result<HttpResponse, Erro
|
|||||||
.body(r.dump()));
|
.body(r.dump()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let app_state = req.app_data().unwrap();
|
|
||||||
let mut result = convention::Response::default();
|
let mut result = convention::Response::default();
|
||||||
result.id = reqjson.id.clone();
|
result.id = reqjson.id.clone();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user