The server module for PXE.js.
Install @pxe/server.
# NPM
npm i @pxe/server
# Yarn
yarn add @pxe/server
These are all @pxe/server module methods, events and declarations.
ServerCreate a server instance.
app.cbreq: http.IncomingMessage: The requestres: http.ServerResponse: The responseThe server callback. Can be used to create HTTP server:
const server = http.createServer(app.cb.bind(app));
// Or even shorter
const server = http.createServer(app);
app.use...m: Middleware[]: The middlewareAdd a middleware to the middleware list. You can add multiple middleware within a single call.
app.onevent: string: The event namehandler: (...args: any[]) => Promise<void> | void: The event listenerAdd an listener of an event.
app.emitevent: string: The event name...args: any[]: The parameter to apply to the function callPromise<void> | void | booleanTrigger the listener of an event.
If the event listener does not exist return false.
app.lsport?: number: The target porthostname?: string: The target hostnamebacklog?: number: The backloglisteningListener: Runs when the server finished startinghttp.ServerStart a server listening for connections. A short way for calling:
const server = http.createServer(app);
server.listen(port, host, backlog, listeningListener);
app.iconpath: string: The icon pathSet the icon of the app.
On each request with request URL equals /favicon.ico the icon is returned.
app.setTkey: string: The keyvalue: T: The valueSave the key value pair to the app storage.
app.getkey: string: The keyGet the key value from the app storage.
errorerr: any: The errorctx: Context: The context object of the current requestTrigger when an error occurred while running the middlewares.
finishctx: Context: The context object of the current requestTrigger after running all the middlewares. the default event handler is the finishResponse method in finishResponse.ts.
RequestMethod"GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH" | "CONNECT" | "TRACE"All the request method.
MIMEType"audio/aac" | "application/x-abiword" | "application/x-freearc" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-csh" | "application/x-cdf" | "text/css" | "text/csv" | "application/msword" | "application/vnd.ms-fontobject" | "application/gzip" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/epub+zip" | "image/gif" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "application/java-archive" | "image/jpeg" | "text/javascript" | "application/json" | "application/ld+json" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "video/mp4" | "application/vnd.apple.installer+xml" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "audio/opus" | "font/otf" | "image/png" | "application/pdf" | "image/svg+xml" | "application/x-httpd-php" | "application/vnd.ms-powerpoint" | "application/vnd.rar" | "application/rtf" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/x-sh" | "application/x-shockwave-flash" | "application/x-tar" | "image/tiff" | "font/ttf" | "video/mp2t" | "text/plain" | "application/vnd.visio" | "audio/wav" | "audio/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "text/xml" | "application/atom+xml" | "application/vnd.mozilla.xul+xml" | "application/zip" | "video/3gpp" | "audio/3gpp" | "video/3gpp2" | "audio/3gpp2" | "application/x-7z-compressed" | "application/x-www-form-urlencoded"All the common MIME types.
Middlewarectx: Context: The current request contextnext: NextFunction: The function that calls the next middleware...args: any[]: The arguments passed by the previous middlewareThe middleware type.
NextFunction..args: any[]: The arguments to pass to the next middlewareThe next function type.
ContextAll the properties of a ctx object.
All the properties of ctx.request.
request.rawhttp.IncomingMessageThe raw HTTP request object. This property is read-only.
request.methodServer.RequestMethodThe request method. This property is read-only.
request.urlstringThis property is read-only. The request URL.
request.headershttp.IncomingHttpHeadersThis property is read-only. Parsed request headers.
request.bodyPromise<any>Get the request body.
request.queryRecord<string, string>This property is read-only. The parsed request query.
All the properties and methods of ctx.response.
response.rawhttp.ServerResponseThe raw HTTP response object. This property is read-only.
response.bodyanyThe response body.
Modify this to modify the response.
If response.body, response.status.code and response.status.message are not set a 404 error is returned to the client.
response.typeServer.MIMETypeThe content type of the response. If this property is not set the content type is chosen base on the response.
response.statuscode?: number: The status code.message?: string: The status message.Set the status code and status message. This property is read-only.
response.headersRecord<string, string | readonly string[] | number>Set the response headers. This property is read-only.
You cannot directly set the headers using response.headers = ....
Instead use Object.assign(response.headers, ...).
response.redirecturl: string: The target URLpermanent?: boolean: Whether this redirect is a permanent redirect or notRedirect to different URL.
All the properties and methods of ctx.cookie.
cookie.optionsServer.CookieOptionsThe cookie options.
cookie.valuestringThe cookie value in string. Modify this property to modify the cookie value.
cookie.removeRemove the cookie. After this call cookie.value cannot be used to set cookie value and cookie.removed is set to true.
cookie.removedbooleanCheck whether the request cookie is removed.
cookie.ivBufferThe cookie initialization vector.
cookie.keystringThe cookie generated secret key.