1
1
#![ deny( clippy:: all) ]
2
2
#![ deny( rust_2018_idioms) ]
3
3
4
+ use crate :: db:: DbPool ;
4
5
use crate :: middleware:: auth;
5
6
use crate :: middleware:: cors:: { cors, Cors } ;
6
- use bb8:: Pool ;
7
- use bb8_postgres:: { tokio_postgres:: NoTls , PostgresConnectionManager } ;
8
7
use hyper:: service:: { make_service_fn, service_fn} ;
9
8
use hyper:: { Body , Error , Method , Request , Response , Server , StatusCode } ;
10
9
use primitives:: adapter:: Adapter ;
@@ -45,7 +44,7 @@ pub struct Application<A: Adapter> {
45
44
adapter : A ,
46
45
logger : Logger ,
47
46
redis : MultiplexedConnection ,
48
- _postgres : Pool < PostgresConnectionManager < NoTls > > ,
47
+ pool : DbPool ,
49
48
_clustered : bool ,
50
49
port : u16 ,
51
50
config : Config ,
@@ -57,7 +56,7 @@ impl<A: Adapter + 'static> Application<A> {
57
56
config : Config ,
58
57
logger : Logger ,
59
58
redis : MultiplexedConnection ,
60
- postgres : Pool < PostgresConnectionManager < NoTls > > ,
59
+ pool : DbPool ,
61
60
clustered : bool ,
62
61
port : u16 ,
63
62
) -> Self {
@@ -66,7 +65,7 @@ impl<A: Adapter + 'static> Application<A> {
66
65
config,
67
66
logger,
68
67
redis,
69
- _postgres : postgres ,
68
+ pool ,
70
69
_clustered : clustered,
71
70
port,
72
71
}
@@ -81,17 +80,19 @@ impl<A: Adapter + 'static> Application<A> {
81
80
let adapter_config = ( self . adapter . clone ( ) , self . config . clone ( ) ) ;
82
81
let redis = self . redis . clone ( ) ;
83
82
let logger = self . logger . clone ( ) ;
83
+ let pool = self . pool . clone ( ) ;
84
84
async move {
85
85
Ok :: < _ , Error > ( service_fn ( move |req| {
86
86
let adapter_config = adapter_config. clone ( ) ;
87
87
let redis = redis. clone ( ) ;
88
88
let logger = logger. clone ( ) ;
89
+ let pool = pool. clone ( ) ;
89
90
async move {
90
91
Ok :: < _ , Error > (
91
92
handle_routing (
92
93
req,
93
94
( & adapter_config. 0 , & adapter_config. 1 ) ,
94
- redis,
95
+ ( pool , redis) ,
95
96
& logger,
96
97
)
97
98
. await ,
@@ -127,7 +128,7 @@ where
127
128
async fn handle_routing (
128
129
req : Request < Body > ,
129
130
( adapter, config) : ( & impl Adapter , & Config ) ,
130
- redis : MultiplexedConnection ,
131
+ ( pool , redis) : ( DbPool , MultiplexedConnection ) ,
131
132
logger : & Logger ,
132
133
) -> Response < Body > {
133
134
let headers = match cors ( & req) {
@@ -149,7 +150,7 @@ async fn handle_routing(
149
150
let mut response = match ( req. uri ( ) . path ( ) , req. method ( ) ) {
150
151
( "/cfg" , & Method :: GET ) => crate :: routes:: cfg:: return_config ( & config) ,
151
152
( route, _) if route. starts_with ( "/channel" ) => {
152
- crate :: routes:: channel:: handle_channel_routes ( req, adapter) . await
153
+ crate :: routes:: channel:: handle_channel_routes ( req, ( & pool , adapter) ) . await
153
154
}
154
155
_ => Err ( ResponseError :: NotFound ) ,
155
156
}
@@ -174,7 +175,8 @@ pub fn not_found() -> Response<Body> {
174
175
response
175
176
}
176
177
177
- pub fn bad_request ( _: Box < dyn std:: error:: Error > ) -> Response < Body > {
178
+ pub fn bad_request ( err : Box < dyn std:: error:: Error > ) -> Response < Body > {
179
+ println ! ( "{:#?}" , err) ;
178
180
let body = Body :: from ( "Bad Request: try again later" ) ;
179
181
let mut response = Response :: new ( body) ;
180
182
let status = response. status_mut ( ) ;
0 commit comments