Skip to content

Commit

Permalink
Merge pull request #135 from sebringrose/hotfixes
Browse files Browse the repository at this point in the history
fix: server onError
  • Loading branch information
sejori authored Feb 28, 2023
2 parents 2fde0a1 + ed5550d commit 836e830
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion handlers/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface staticHandlerOptions extends HandlerOptions {
* Optionally: provide custom headers and/or body transform fcn.
*
* @param fileURL: URL object of file address
* @param opts: (optional) HandlerOptions
* @param opts: (optional) staticHandlerOptions
* @returns Handler: (ctx: RequestContext) => Promise<Response>
*/
export const staticHandler = (fileURL: URL, opts: staticHandlerOptions = {}): Handler => async (_ctx: RequestContext) => {
Expand Down
11 changes: 8 additions & 3 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ export class Server extends Router {
* Start listening to HTTP requests.
* @param port: number
* @param onListen: onListen callback function
* @param onError: onListen callback function
* @param onError: error handler
*/
async listen(port?: number, onListen?: (server: stdServer) => void): Promise<void> {
async listen(
port?: number,
onListen?: (server: stdServer) => void,
onError?: (error: unknown) => Response | Promise<Response>
): Promise<void> {
if (port) this.port = port

this.stdServer = new stdServer({
port: this.port,
handler: (request: Request) => this.requestHandler.call(this, request)
handler: (request: Request) => this.requestHandler.call(this, request),
onError
})

if (onListen) {
Expand Down

0 comments on commit 836e830

Please sign in to comment.