You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What: Implement logic so that the following syntax works:
classHomeResourceextendsDrash.Http.Resource{staticpaths=["/"];publicGET(){this.response.body="Hello World!";returnthis.response;}}constserver=newDrash.Http.Server({response_output: "text/html",resources: [HomeResource]});awaitserver.run({// the await here should be optionalhostname: "localhost",port: 1447});console.log("server running");console.log(server);server.close()console.log("server stopped");
This requires run() and runTLS() to use an IIFE when awaiting for requests from the Deno server.
Benchmarks were initially run on the implementation below and there was a small performance gain. Around ~2k req/sec gain.
Why: Syntax allows for cleaner implementation in cases where the server needs to be awaited on before running any subsequent code. This also ensures the developer that the server is running before any subsequent code is processed.
Acceptance Criteria
Documentation showing optional await keyword on server.run() and server.runTLS()
Tests pass without being refactored
Example Pseudo Code (for implementation)
/** * @description * Run the Deno server at the hostname specified in the configs. This * method takes each HTTP request and creates a new and more workable * request object and passes it to * `Drash.Http.Server.handleHttpRequest()`. * * @param HTTPOptions options * The HTTPOptions interface from https://deno.land/std/http/server.ts. * * @return Promise<void> * This method just listens for requests at the hostname you provide in the * configs. */publicasyncrun(options: HTTPOptions): Promise<void>{if(!options.hostname){options.hostname=this.hostname;}if(!options.port){options.port=1447;}this.hostname=options.hostname;this.deno_server=serve(options);(async()=>{forawait(constrequestofthis.deno_server){try{this.handleHttpRequest(request);}catch(error){this.handleHttpRequestError(request,this.httpErrorResponse(500));}}})();returnthis.deno_server;}/** * @description * Run the Deno server at the hostname specified in the configs as an * HTTPS Server. This method takes each HTTP request and creates a new and * more workable request object and passes it to * `Drash.Http.Server.handleHttpRequest()`. * * @param HTTPSOptions options * The HTTPSOptions interface from https://deno.land/std/http/server.ts. * * @return Promise<void> * This method just listens for requests at the hostname you provide in * the configs. */publicasyncrunTLS(options: HTTPSOptions): Promise<void>{if(!options.hostname){options.hostname=this.hostname;}if(!options.port){options.port=1447;}this.hostname=options.hostname;this.deno_server=serveTLS(options);(async()=>{forawait(constrequestofthis.deno_server){try{this.handleHttpRequest(request);}catch(error){this.handleHttpRequestError(request,this.httpErrorResponse(500));}}})();returnthis.deno_server;}
The text was updated successfully, but these errors were encountered:
Summary
What: Implement logic so that the following syntax works:
This requires
run()
andrunTLS()
to use an IIFE when awaiting for requests from the Deno server.Benchmarks were initially run on the implementation below and there was a small performance gain. Around ~2k req/sec gain.
Why: Syntax allows for cleaner implementation in cases where the server needs to be
await
ed on before running any subsequent code. This also ensures the developer that the server is running before any subsequent code is processed.Acceptance Criteria
await
keyword onserver.run()
andserver.runTLS()
Example Pseudo Code (for implementation)
The text was updated successfully, but these errors were encountered: