33static GLOBAL : mimalloc:: MiMalloc = mimalloc:: MiMalloc ;
44
55use ntex:: http:: header:: { CONTENT_TYPE , SERVER } ;
6- use ntex:: http:: { HttpService , KeepAlive , Request , Response , StatusCode } ;
7- use ntex:: service:: { Service , ServiceCtx , ServiceFactory } ;
8- use ntex:: web:: { Error , HttpResponse } ;
9- use ntex:: { time:: Seconds , util:: PoolId } ;
6+ use ntex:: http:: { HttpService , Request , Response , StatusCode } ;
7+ use ntex:: service:: { cfg:: SharedCfg , Service , ServiceCtx , ServiceFactory } ;
8+ use ntex:: { web:: Error , web:: HttpResponse } ;
109
1110mod db;
1211mod utils;
@@ -64,13 +63,13 @@ impl Service<Request> for App {
6463
6564struct AppFactory ;
6665
67- impl ServiceFactory < Request > for AppFactory {
66+ impl ServiceFactory < Request , SharedCfg > for AppFactory {
6867 type Response = Response ;
6968 type Error = Error ;
7069 type Service = App ;
7170 type InitError = ( ) ;
7271
73- async fn create ( & self , _: ( ) ) -> Result < Self :: Service , Self :: InitError > {
72+ async fn create ( & self , _: SharedCfg ) -> Result < Self :: Service , Self :: InitError > {
7473 const DB_URL : & str =
7574 "postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world" ;
7675
@@ -85,18 +84,8 @@ async fn main() -> std::io::Result<()> {
8584 ntex:: server:: build ( )
8685 . backlog ( 1024 )
8786 . enable_affinity ( )
88- . bind ( "techempower" , "0.0.0.0:8080" , |cfg| {
89- cfg. memory_pool ( PoolId :: P1 ) ;
90- PoolId :: P1 . set_read_params ( 65535 , 2048 ) ;
91- PoolId :: P1 . set_write_params ( 65535 , 2048 ) ;
92-
93- HttpService :: build ( )
94- . keep_alive ( KeepAlive :: Os )
95- . client_timeout ( Seconds ( 0 ) )
96- . headers_read_rate ( Seconds :: ZERO , Seconds :: ZERO , 0 )
97- . payload_read_rate ( Seconds :: ZERO , Seconds :: ZERO , 0 )
98- . h1 ( AppFactory )
99- } ) ?
87+ . bind ( "tfb" , "0.0.0.0:8080" , async |_| HttpService :: h1 ( AppFactory ) ) ?
88+ . config ( "tfb" , utils:: config ( ) )
10089 . run ( )
10190 . await
10291}
0 commit comments