File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -78,10 +78,15 @@ async function serve(args1, args2) {
78
78
opts [ 'handler' ] = args1 ;
79
79
} else if ( typeof args1 === 'object' && typeof args2 === 'function' ) {
80
80
opts [ 'handler' ] = args2 ;
81
- } else {
82
- if ( typeof handler !== 'function' ) {
83
- throw new TypeError ( 'A handler function must be provided.' ) ;
81
+ } else if ( typeof args1 === 'object' ) {
82
+ if ( typeof args1 [ 'handler' ] === 'function' ) {
83
+ opts [ 'handler' ] = args1 [ 'handler' ] ;
84
+ }
85
+ if ( typeof args1 [ 'onListen' ] === 'function' ) {
86
+ opts [ 'onListen' ] = args1 [ 'onListen' ] ;
84
87
}
88
+ } else {
89
+ throw new TypeError ( 'A handler function must be provided.' ) ;
85
90
}
86
91
87
92
let serve ;
@@ -90,7 +95,14 @@ async function serve(args1, args2) {
90
95
serve = serveHttp ( conn ) ;
91
96
for await ( const e of serve ) {
92
97
try {
93
- const res = await opts [ 'handler' ] ( e . request ) ;
98
+ const res = await opts [ 'handler' ] ( e . request , {
99
+ remoteAddr : {
100
+ port : opts . port ,
101
+ hostname : opts . hostname ,
102
+ transport : opts . transport
103
+ }
104
+ } ) ;
105
+
94
106
e . respondWith ( res ) ;
95
107
} catch ( error ) {
96
108
console . error ( error ) ;
@@ -100,6 +112,11 @@ async function serve(args1, args2) {
100
112
} ;
101
113
102
114
const finished = ( async ( ) => {
115
+ opts [ 'onListen' ] ?. ( {
116
+ hostname : opts . hostname ,
117
+ port : opts . port
118
+ } ) ;
119
+
103
120
for await ( const conn of listener ) {
104
121
handleHttp ( conn ) ;
105
122
}
You can’t perform that action at this time.
0 commit comments