@@ -5,11 +5,11 @@ const Response = require('./response.js') // Import the response object
5
5
const { warn } = require ( 'console' )
6
6
7
7
/**
8
- *
8
+ *
9
9
* @param {Function } callback - The callback function to handle incoming connections.
10
10
* @param {Object } context - The context object containing the server configuration.
11
11
* @returns A server socket object.
12
- *
12
+ *
13
13
* @example
14
14
* ```javascript
15
15
* const server = getSocket(handler, {
@@ -28,12 +28,11 @@ function getSocket (callback, context) {
28
28
return net . createServer ( Socket => callback ( Socket , context ) )
29
29
}
30
30
31
-
32
31
/**
33
- *
32
+ *
34
33
* @param {Socket } socket - The socket object for the response.
35
34
* @param {Object } context - The context object containing the server configuration.
36
- * @returns A server socket object.
35
+ * @returns A server socket object.
37
36
*/
38
37
function handler ( socket , context ) {
39
38
socket . on ( 'data' , ( data ) => {
@@ -47,8 +46,8 @@ function handler (socket, context) {
47
46
console . error ( 'Error parsing HTTP request:' , error )
48
47
res . sendStatus ( 400 ) // Send a Bad Request status
49
48
return null
50
- } ) ;
51
- } ) ;
49
+ } )
50
+ } )
52
51
}
53
52
54
53
/**
@@ -152,7 +151,7 @@ function extractParams (routePath, actualPath) {
152
151
*/
153
152
class Server {
154
153
socket
155
- /**
154
+ /**
156
155
* Creates a new Server instance
157
156
* @constructor
158
157
*/
@@ -163,15 +162,15 @@ class Server {
163
162
* @private
164
163
*/
165
164
this . socket = getSocket ( handler , this )
166
- /**
165
+ /**
167
166
* Array of routes registered with the server
168
167
* @type {Array }
169
168
* @private
170
169
*/
171
170
this . routes = [ ]
172
171
}
173
172
174
- /**
173
+ /**
175
174
* Starts the server listening on specified port
176
175
* @param {number } PORT - The port number to listen on
177
176
* @param {Function } callback - Callback function to execute when server starts listening
@@ -188,16 +187,16 @@ class Server {
188
187
}
189
188
190
189
class Hasty extends Server {
191
- /**
190
+ /**
192
191
* Creates a new Hasty server instance
193
192
* @constructor
194
193
*/
195
194
constructor ( ) {
196
195
super ( )
197
- /**
196
+ /**
198
197
* Collection of middleware functions
199
198
* @type {Array<Function> }
200
- * @private
199
+ * @private
201
200
*/
202
201
this . enableCors = false // default to false
203
202
/**
@@ -228,71 +227,72 @@ class Hasty extends Server {
228
227
cors ( enable ) {
229
228
this . enableCors = enable
230
229
}
230
+
231
231
/**
232
232
* GET
233
- *
234
- * @param {string } path
235
- * @param {Function } callback
233
+ *
234
+ * @param {string } path
235
+ * @param {Function } callback
236
236
*/
237
237
get ( path , callback ) {
238
238
this . setRoute ( 'GET' , { callback, path } )
239
239
}
240
240
241
241
/**
242
242
* POST
243
- *
244
- * @param {string } path
245
- * @param {Function } callback
243
+ *
244
+ * @param {string } path
245
+ * @param {Function } callback
246
246
*/
247
247
post ( path , callback ) {
248
248
this . setRoute ( 'POST' , { callback, path } )
249
249
}
250
250
251
251
/**
252
252
* PUT
253
- *
254
- * @param {string } path
255
- * @param {Function } callback
253
+ *
254
+ * @param {string } path
255
+ * @param {Function } callback
256
256
*/
257
257
put ( path , callback ) {
258
258
this . setRoute ( 'PUT' , { callback, path } )
259
259
}
260
260
261
261
/**
262
262
* DELETE
263
- *
264
- * @param {string } path
265
- * @param {Function } callback
263
+ *
264
+ * @param {string } path
265
+ * @param {Function } callback
266
266
*/
267
267
delete ( path , callback ) {
268
268
this . setRoute ( 'DELETE' , { callback, path } )
269
269
}
270
270
271
271
/**
272
272
* PATCH
273
- *
274
- * @param {string } path
275
- * @param {Function } callback
273
+ *
274
+ * @param {string } path
275
+ * @param {Function } callback
276
276
*/
277
277
patch ( path , callback ) {
278
278
this . setRoute ( 'PATCH' , { callback, path } )
279
279
}
280
280
281
281
/**
282
282
* HEAD
283
- *
284
- * @param {string } path
285
- * @param {Function } callback
283
+ *
284
+ * @param {string } path
285
+ * @param {Function } callback
286
286
*/
287
287
head ( path , callback ) {
288
288
this . setRoute ( 'HEAD' , { callback, path } )
289
289
}
290
290
291
291
/**
292
292
* OPTIONS
293
- *
294
- * @param {string } path
295
- * @param {Function } callback
293
+ *
294
+ * @param {string } path
295
+ * @param {Function } callback
296
296
*/
297
297
options ( path , callback ) {
298
298
this . setRoute ( 'OPTIONS' , { callback, path } )
0 commit comments