diff --git a/server/index.js b/server/index.js index d15adb8..424269c 100644 --- a/server/index.js +++ b/server/index.js @@ -5,11 +5,11 @@ const Response = require('./response.js') // Import the response object const { warn } = require('console') /** - * + * * @param {Function} callback - The callback function to handle incoming connections. * @param {Object} context - The context object containing the server configuration. * @returns A server socket object. - * + * * @example * ```javascript * const server = getSocket(handler, { @@ -28,12 +28,11 @@ function getSocket (callback, context) { return net.createServer(Socket => callback(Socket, context)) } - /** - * + * * @param {Socket} socket - The socket object for the response. * @param {Object} context - The context object containing the server configuration. - * @returns A server socket object. + * @returns A server socket object. */ function handler (socket, context) { socket.on('data', (data) => { @@ -47,8 +46,8 @@ function handler (socket, context) { console.error('Error parsing HTTP request:', error) res.sendStatus(400) // Send a Bad Request status return null - }); - }); + }) + }) } /** @@ -152,7 +151,7 @@ function extractParams (routePath, actualPath) { */ class Server { socket - /** + /** * Creates a new Server instance * @constructor */ @@ -163,7 +162,7 @@ class Server { * @private */ this.socket = getSocket(handler, this) - /** + /** * Array of routes registered with the server * @type {Array} * @private @@ -171,7 +170,7 @@ class Server { this.routes = [] } - /** + /** * Starts the server listening on specified port * @param {number} PORT - The port number to listen on * @param {Function} callback - Callback function to execute when server starts listening @@ -188,16 +187,16 @@ class Server { } class Hasty extends Server { - /** + /** * Creates a new Hasty server instance * @constructor */ constructor () { super() - /** + /** * Collection of middleware functions * @type {Array} - * @private + * @private */ this.enableCors = false // default to false /** @@ -228,11 +227,12 @@ class Hasty extends Server { cors (enable) { this.enableCors = enable } + /** * GET - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ get (path, callback) { this.setRoute('GET', { callback, path }) @@ -240,9 +240,9 @@ class Hasty extends Server { /** * POST - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ post (path, callback) { this.setRoute('POST', { callback, path }) @@ -250,9 +250,9 @@ class Hasty extends Server { /** * PUT - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ put (path, callback) { this.setRoute('PUT', { callback, path }) @@ -260,9 +260,9 @@ class Hasty extends Server { /** * DELETE - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ delete (path, callback) { this.setRoute('DELETE', { callback, path }) @@ -270,9 +270,9 @@ class Hasty extends Server { /** * PATCH - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ patch (path, callback) { this.setRoute('PATCH', { callback, path }) @@ -280,9 +280,9 @@ class Hasty extends Server { /** * HEAD - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ head (path, callback) { this.setRoute('HEAD', { callback, path }) @@ -290,9 +290,9 @@ class Hasty extends Server { /** * OPTIONS - * - * @param {string} path - * @param {Function} callback + * + * @param {string} path + * @param {Function} callback */ options (path, callback) { this.setRoute('OPTIONS', { callback, path }) diff --git a/server/response.js b/server/response.js index 5da95ee..7af44bd 100644 --- a/server/response.js +++ b/server/response.js @@ -2,7 +2,6 @@ const fs = require('fs') const { lookupMimeType } = require('../lib/utils') const path = require('path') - const STATUS_CODES = Object.freeze({ 200: 'OK', 201: 'Created', @@ -25,16 +24,15 @@ const STATUS_CODES = Object.freeze({ 503: 'Service Unavailable' }) - /** * Response class for handling HTTP responses. - * + * * @class Response - * + * * @param {Socket} socket - The socket object for the response. * @param {boolean} enableCors - Enable Cross-Origin Resource Sharing (CORS). * @param {string} statusTextMap - Map of status codes to status texts. - * @example + * @example * ```javascript const Response = require('./response.js'); @@ -68,7 +66,7 @@ class Response { } /** - * + * * @param {number} code - The HTTP status code. * @returns - The Response instance. */ @@ -81,7 +79,7 @@ class Response { } /** - * + * * @param {string} key - The header key. * @param {string} value - The header value. * @returns - The Response instance. @@ -115,7 +113,7 @@ class Response { } /** - * + * * @param {string} data - The data to send. * @returns - If the data is an object or array, send as JSON */ @@ -144,7 +142,7 @@ class Response { } /** - * + * * @param {number} statusCode - The HTTP status code. * Updates the status code and sends the status code as a response. */ @@ -156,7 +154,7 @@ class Response { } /** - * + * * @param {*} data - The data to send. */ json (data) { @@ -172,7 +170,7 @@ class Response { } /** - * + * * @param {*} file - The file to send. */ sendFile (file) { @@ -208,7 +206,7 @@ class Response { } /** - * + * * @param {*} file - The file to send. * @param {*} filename - The filename to send. */