web-dev-server
Version:
Node.js simple http server for common development or training purposes.
38 lines (37 loc) • 1.55 kB
TypeScript
import { Server } from "../Server";
import { Request } from "../Request";
import { Response } from "../Response";
/**
* @summary
* Class to handle directory requests.
* When there is first request to directory with default
* `index.js` script inside, this class is automatically
* created and method `Start()` is executed.
* All request are normally handled by method `HttpHandle()`.
* If there is detected any file change inside this file
* or inside file included in this file (on development server
* instance), the module `web-dev-server` automaticly reloads
* all necesssary dependent source codes, stops previous instance
* by method `Stop`() and recreates this application instance again
* by `Start()` method. The same realoding procedure is executed,
* if there is any unhandled error inside method `HttpHandle()`
* (to develop more comfortably).
*/
export interface IApplication {
/**
* @summary Application start point.
*/
Start?(server: Server, firstRequest: Request, firstResponse: Response): Promise<void>;
/**
* @summary
* This method is executed each request to directory with
* `index.js` script inside or into any non-existing directory,
* inside directory with this script.
*/
HttpHandle?(request: Request, response: Response): Promise<void>;
/**
* @summary Application end point, called on unhandled error
* (on development server instance) or on server stop event.
*/
Stop?(server: Server): Promise<void>;
}