1- import Engine from "./engine.ts" ;
2- import "./docs.d.ts" ;
1+ import Engine from "./engine/mod .ts" ;
2+ const engine = Engine ;
33
4- const engine : Engine = new Engine ( ) ;
5- engine . port = 80 ;
6- engine . host = "0.0.0.0" ;
7- engine . upgrade = true ;
8- engine . on ( "connect" , async function ( { socket, client} : HttpSocket ) : Promise < void > {
4+
5+ engine . on ( "connect" , async function ( { socket, client} : Engine . HttpSocket ) : Promise < void > {
96 console . log ( client ) ;
7+ if ( ! client ) return ;
108
119 if ( ! client . isValid ) {
1210 socket . status = 400 ;
@@ -29,22 +27,22 @@ engine.on("connect",async function({socket,client}: HttpSocket): Promise<void>{
2927 }
3028} ) ;
3129engine . on ( "http2" , h2cHandler ) ;
32- async function handler ( sock :HttpSocket | PseudoHttpSocket ) {
30+ async function handler ( sock :Engine . HttpSocket | Engine . PseudoHttpSocket ) {
3331 sock . setHeader ( "Content-Type" , "text/plain" ) ;
3432 sock . close ( JSON . stringify ( sock . client ) ) ;
3533} ;
36- async function h2cHandler ( socket : Http2Socket ) {
34+ async function h2cHandler ( socket : Engine . Http2Socket ) {
3735 socket . on ( "error" , console . error ) ;
3836 await socket . ready ;
3937 console . log ( "http2" ) ;
40- socket . on ( "stream" , async function ( stream :Http2Stream ) {
38+ socket . on ( "stream" , async function ( stream :Engine . Http2Stream ) {
4139 console . log ( "http2 stream" ) ;
4240 const ps = stream . pseudo ( ) ;
4341 handler ( ps ) ;
4442 } )
4543} ;
4644engine . on ( "error" , console . error ) ;
47- engine . start ( ) ;
45+ engine . start ( 8080 ) ;
4846console . log ( "listening" ) ;
4947
5048globalThis . engine = engine ;
0 commit comments