Skip to content

style: format code with StandardJS #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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) => {
Expand All @@ -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
});
});
})
})
}

/**
Expand Down Expand Up @@ -152,7 +151,7 @@ function extractParams (routePath, actualPath) {
*/
class Server {
socket
/**
/**
* Creates a new Server instance
* @constructor
*/
Expand All @@ -163,15 +162,15 @@ class Server {
* @private
*/
this.socket = getSocket(handler, this)
/**
/**
* Array of routes registered with the server
* @type {Array}
* @private
*/
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
Expand All @@ -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<Function>}
* @private
* @private
*/
this.enableCors = false // default to false
/**
Expand Down Expand Up @@ -228,71 +227,72 @@ 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 })
}

/**
* POST
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
post (path, callback) {
this.setRoute('POST', { callback, path })
}

/**
* PUT
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
put (path, callback) {
this.setRoute('PUT', { callback, path })
}

/**
* DELETE
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
delete (path, callback) {
this.setRoute('DELETE', { callback, path })
}

/**
* PATCH
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
patch (path, callback) {
this.setRoute('PATCH', { callback, path })
}

/**
* HEAD
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
head (path, callback) {
this.setRoute('HEAD', { callback, path })
}

/**
* OPTIONS
*
* @param {string} path
* @param {Function} callback
*
* @param {string} path
* @param {Function} callback
*/
options (path, callback) {
this.setRoute('OPTIONS', { callback, path })
Expand Down
22 changes: 10 additions & 12 deletions server/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');

Expand Down Expand Up @@ -68,7 +66,7 @@ class Response {
}

/**
*
*
* @param {number} code - The HTTP status code.
* @returns - The Response instance.
*/
Expand All @@ -81,7 +79,7 @@ class Response {
}

/**
*
*
* @param {string} key - The header key.
* @param {string} value - The header value.
* @returns - The Response instance.
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -156,7 +154,7 @@ class Response {
}

/**
*
*
* @param {*} data - The data to send.
*/
json (data) {
Expand All @@ -172,7 +170,7 @@ class Response {
}

/**
*
*
* @param {*} file - The file to send.
*/
sendFile (file) {
Expand Down Expand Up @@ -208,7 +206,7 @@ class Response {
}

/**
*
*
* @param {*} file - The file to send.
* @param {*} filename - The filename to send.
*/
Expand Down
Loading