1
- pub mod body;
2
- pub mod request;
3
- pub mod response;
4
- use body:: Body ;
5
- pub use lambda_http;
6
- use lambda_http:: { service_fn, tower:: ServiceBuilder } ;
7
- pub use lambda_runtime;
1
+ mod body;
2
+ mod request;
3
+ mod response;
8
4
use lambda_runtime:: LambdaEvent ;
9
5
use request:: { VercelEvent , VercelRequest } ;
10
- pub use response:: IntoResponse ;
11
- use response:: VercelResponse ;
6
+ use response:: EventResponse ;
12
7
use std:: future:: Future ;
13
8
use tracing:: { debug, error} ;
14
9
15
10
pub type Request = lambda_http:: http:: Request < Body > ;
16
11
pub type Error = lambda_http:: Error ;
12
+ pub type Event < ' a > = LambdaEvent < VercelEvent < ' a > > ;
13
+ pub use body:: Body ;
14
+ pub use lambda_http:: http:: StatusCode ;
15
+ pub use lambda_http:: service_fn;
16
+ pub use lambda_http:: tower:: ServiceBuilder ;
17
+ pub use lambda_http:: Response ;
18
+ pub use lambda_runtime:: run as run_service;
17
19
18
- pub async fn run < T : FnMut ( Request ) -> F , F : Future < Output = Result < impl IntoResponse , Error > > > (
20
+ pub async fn run < T : FnMut ( Request ) -> F , F : Future < Output = Result < Response < Body > , Error > > > (
19
21
f : T ,
20
22
) -> Result < ( ) , Error > {
21
23
let handler = ServiceBuilder :: new ( )
@@ -26,8 +28,8 @@ pub async fn run<T: FnMut(Request) -> F, F: Future<Output = Result<impl IntoResp
26
28
lambda_runtime:: run ( handler) . await
27
29
}
28
30
29
- pub fn process_request ( lambda_event : LambdaEvent < VercelEvent > ) -> lambda_http :: http :: Request < Body > {
30
- let ( event, _context) = lambda_event . into_parts ( ) ;
31
+ pub fn process_request ( event : Event ) -> Request {
32
+ let ( event, _context) = event . into_parts ( ) ;
31
33
let parse_result = serde_json:: from_str :: < VercelRequest > ( & event. body ) ;
32
34
33
35
match parse_result {
@@ -44,6 +46,6 @@ pub fn process_request(lambda_event: LambdaEvent<VercelEvent>) -> lambda_http::h
44
46
}
45
47
}
46
48
47
- pub fn process_response ( response : impl IntoResponse ) -> VercelResponse {
48
- VercelResponse :: from ( response. into_response ( ) )
49
+ pub fn process_response ( response : Response < Body > ) -> EventResponse {
50
+ EventResponse :: from ( response)
49
51
}
0 commit comments