@oxog/spark 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +632 -315
- package/LICENSE +20 -20
- package/README.md +288 -241
- package/package.json +83 -89
- package/src/core/application.js +1068 -956
- package/src/core/context.js +1098 -830
- package/src/core/middleware.js +303 -217
- package/src/index.js +183 -280
- package/src/middleware/body-parser.js +482 -526
- package/src/middleware/cache.js +177 -170
- package/src/middleware/compression.js +177 -182
- package/src/middleware/cors.js +176 -95
- package/src/middleware/health.js +219 -218
- package/src/middleware/logger.js +195 -194
- package/src/middleware/metrics.js +339 -327
- package/src/middleware/rate-limit.js +367 -319
- package/src/middleware/security.js +442 -332
- package/src/middleware/session.js +647 -529
- package/src/middleware/static.js +404 -299
- package/src/router/layer.js +197 -117
- package/src/router/route.js +149 -123
- package/src/router/router.js +703 -755
- package/src/utils/async-handler.js +145 -147
- package/src/utils/context-pool.js +83 -82
- package/src/utils/regex-validator.js +187 -163
- package/src/utils/safe-json.js +110 -0
- package/types/index.d.ts +536 -291
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -242
- package/dist/core/application.js +0 -959
- package/dist/core/context.js +0 -833
- package/dist/core/middleware.js +0 -220
- package/dist/core/request.js +0 -335
- package/dist/core/response.js +0 -377
- package/dist/index.js +0 -280
- package/dist/middleware/body-parser.js +0 -528
- package/dist/middleware/cache.js +0 -173
- package/dist/middleware/compression.js +0 -185
- package/dist/middleware/cors.js +0 -97
- package/dist/middleware/health.js +0 -221
- package/dist/middleware/index.js +0 -23
- package/dist/middleware/logger.js +0 -197
- package/dist/middleware/metrics.js +0 -330
- package/dist/middleware/rate-limit.js +0 -322
- package/dist/middleware/security.js +0 -335
- package/dist/middleware/session.js +0 -532
- package/dist/middleware/static.js +0 -301
- package/dist/package.json +0 -62
- package/dist/router/layer.js +0 -119
- package/dist/router/route.js +0 -125
- package/dist/router/router.js +0 -758
- package/dist/types/index.d.ts +0 -291
- package/dist/utils/async-handler.js +0 -150
- package/dist/utils/cache.js +0 -443
- package/dist/utils/context-pool.js +0 -85
- package/dist/utils/error-types.js +0 -134
- package/dist/utils/http.js +0 -415
- package/dist/utils/regex-validator.js +0 -166
- package/src/core/request.js +0 -335
- package/src/core/response.js +0 -377
- package/src/middleware/index.js +0 -23
- package/src/utils/cache.js +0 -443
- package/src/utils/error-types.js +0 -134
- package/src/utils/http.js +0 -415
package/dist/core/response.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { STATUS_CODES } = require('http');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const { promisify } = require('util');
|
|
7
|
-
const stat = promisify(fs.stat);
|
|
8
|
-
const readFile = promisify(fs.readFile);
|
|
9
|
-
|
|
10
|
-
class Response {
|
|
11
|
-
constructor(res) {
|
|
12
|
-
this.res = res;
|
|
13
|
-
this.statusCode = 200;
|
|
14
|
-
this.headers = {};
|
|
15
|
-
this.locals = {};
|
|
16
|
-
this.finished = false;
|
|
17
|
-
this.headersSent = false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
status(code) {
|
|
21
|
-
this.statusCode = code;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
set(field, value) {
|
|
26
|
-
if (typeof field === 'object') {
|
|
27
|
-
Object.assign(this.headers, field);
|
|
28
|
-
} else {
|
|
29
|
-
this.headers[field.toLowerCase()] = value;
|
|
30
|
-
}
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get(field) {
|
|
35
|
-
return this.headers[field.toLowerCase()];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
header(field, value) {
|
|
39
|
-
return this.set(field, value);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setHeader(name, value) {
|
|
43
|
-
return this.set(name, value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getHeader(name) {
|
|
47
|
-
return this.get(name);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
removeHeader(name) {
|
|
51
|
-
delete this.headers[name.toLowerCase()];
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
append(field, value) {
|
|
56
|
-
const existing = this.get(field);
|
|
57
|
-
if (existing) {
|
|
58
|
-
this.set(field, Array.isArray(existing) ? existing.concat(value) : [existing, value]);
|
|
59
|
-
} else {
|
|
60
|
-
this.set(field, value);
|
|
61
|
-
}
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
cookie(name, value, options = {}) {
|
|
66
|
-
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
|
67
|
-
|
|
68
|
-
if (options.domain) {
|
|
69
|
-
cookieString += `; Domain=${options.domain}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (options.path) {
|
|
73
|
-
cookieString += `; Path=${options.path}`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (options.expires) {
|
|
77
|
-
cookieString += `; Expires=${options.expires.toUTCString()}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (options.maxAge) {
|
|
81
|
-
cookieString += `; Max-Age=${options.maxAge}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (options.httpOnly) {
|
|
85
|
-
cookieString += '; HttpOnly';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (options.secure) {
|
|
89
|
-
cookieString += '; Secure';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (options.sameSite) {
|
|
93
|
-
cookieString += `; SameSite=${options.sameSite}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this.append('Set-Cookie', cookieString);
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
clearCookie(name, options = {}) {
|
|
101
|
-
const clearOptions = {
|
|
102
|
-
...options,
|
|
103
|
-
expires: new Date(0),
|
|
104
|
-
maxAge: 0
|
|
105
|
-
};
|
|
106
|
-
return this.cookie(name, '', clearOptions);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
redirect(url, status = 302) {
|
|
110
|
-
this.status(status);
|
|
111
|
-
this.set('Location', url);
|
|
112
|
-
this.end();
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
location(url) {
|
|
117
|
-
this.set('Location', url);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
links(links) {
|
|
122
|
-
let linkHeader = this.get('Link') || '';
|
|
123
|
-
|
|
124
|
-
Object.keys(links).forEach(rel => {
|
|
125
|
-
if (linkHeader) linkHeader += ', ';
|
|
126
|
-
linkHeader += `<${links[rel]}>; rel="${rel}"`;
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
this.set('Link', linkHeader);
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
type(type) {
|
|
134
|
-
const mimeTypes = {
|
|
135
|
-
html: 'text/html',
|
|
136
|
-
json: 'application/json',
|
|
137
|
-
xml: 'application/xml',
|
|
138
|
-
text: 'text/plain',
|
|
139
|
-
png: 'image/png',
|
|
140
|
-
jpg: 'image/jpeg',
|
|
141
|
-
jpeg: 'image/jpeg',
|
|
142
|
-
gif: 'image/gif',
|
|
143
|
-
css: 'text/css',
|
|
144
|
-
js: 'application/javascript',
|
|
145
|
-
pdf: 'application/pdf'
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const contentType = mimeTypes[type] || type;
|
|
149
|
-
this.set('Content-Type', contentType);
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
format(obj) {
|
|
154
|
-
const keys = Object.keys(obj);
|
|
155
|
-
const accepts = this.req.accepts(keys);
|
|
156
|
-
|
|
157
|
-
if (accepts) {
|
|
158
|
-
this.type(accepts);
|
|
159
|
-
obj[accepts](this.req, this);
|
|
160
|
-
} else {
|
|
161
|
-
this.status(406).send('Not Acceptable');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
attachment(filename) {
|
|
168
|
-
if (filename) {
|
|
169
|
-
this.type(path.extname(filename));
|
|
170
|
-
this.set('Content-Disposition', `attachment; filename="${filename}"`);
|
|
171
|
-
} else {
|
|
172
|
-
this.set('Content-Disposition', 'attachment');
|
|
173
|
-
}
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
json(obj) {
|
|
178
|
-
this.type('json');
|
|
179
|
-
this.send(JSON.stringify(obj));
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
jsonp(obj) {
|
|
184
|
-
const callback = this.req.query.callback || 'callback';
|
|
185
|
-
this.type('text/javascript');
|
|
186
|
-
this.send(`${callback}(${JSON.stringify(obj)})`);
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
send(body) {
|
|
191
|
-
if (this.finished) {
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.writeHead();
|
|
196
|
-
|
|
197
|
-
if (body === null || body === undefined) {
|
|
198
|
-
this.res.end();
|
|
199
|
-
} else if (typeof body === 'string') {
|
|
200
|
-
if (!this.get('Content-Type')) {
|
|
201
|
-
this.type('html');
|
|
202
|
-
}
|
|
203
|
-
this.res.end(body);
|
|
204
|
-
} else if (Buffer.isBuffer(body)) {
|
|
205
|
-
if (!this.get('Content-Type')) {
|
|
206
|
-
this.type('application/octet-stream');
|
|
207
|
-
}
|
|
208
|
-
this.res.end(body);
|
|
209
|
-
} else {
|
|
210
|
-
this.json(body);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
this.finished = true;
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async sendFile(filePath, options = {}) {
|
|
218
|
-
try {
|
|
219
|
-
const stats = await stat(filePath);
|
|
220
|
-
|
|
221
|
-
if (!stats.isFile()) {
|
|
222
|
-
return this.status(404).send('File not found');
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const ext = path.extname(filePath);
|
|
226
|
-
this.type(ext);
|
|
227
|
-
|
|
228
|
-
if (options.maxAge) {
|
|
229
|
-
this.set('Cache-Control', `public, max-age=${options.maxAge}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
this.set('Content-Length', stats.size);
|
|
233
|
-
this.set('Last-Modified', stats.mtime.toUTCString());
|
|
234
|
-
|
|
235
|
-
const etag = `"${stats.size}-${stats.mtime.getTime()}"`;
|
|
236
|
-
this.set('ETag', etag);
|
|
237
|
-
|
|
238
|
-
if (this.req.headers['if-none-match'] === etag) {
|
|
239
|
-
return this.status(304).end();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (options.headers) {
|
|
243
|
-
this.set(options.headers);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
this.writeHead();
|
|
247
|
-
|
|
248
|
-
const stream = fs.createReadStream(filePath);
|
|
249
|
-
stream.pipe(this.res);
|
|
250
|
-
|
|
251
|
-
stream.on('end', () => {
|
|
252
|
-
this.finished = true;
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
stream.on('error', (error) => {
|
|
256
|
-
this.status(500).send('Internal Server Error');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
} catch (error) {
|
|
260
|
-
this.status(404).send('File not found');
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
async sendStatus(statusCode) {
|
|
267
|
-
this.status(statusCode);
|
|
268
|
-
this.send(STATUS_CODES[statusCode] || 'Unknown Status');
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
download(filePath, filename, options = {}) {
|
|
273
|
-
const name = filename || path.basename(filePath);
|
|
274
|
-
this.attachment(name);
|
|
275
|
-
return this.sendFile(filePath, options);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
render(view, locals = {}, callback) {
|
|
279
|
-
if (typeof locals === 'function') {
|
|
280
|
-
callback = locals;
|
|
281
|
-
locals = {};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const renderLocals = { ...this.locals, ...locals };
|
|
285
|
-
|
|
286
|
-
if (this.app.render) {
|
|
287
|
-
this.app.render(view, renderLocals, (err, html) => {
|
|
288
|
-
if (err) {
|
|
289
|
-
if (callback) return callback(err);
|
|
290
|
-
throw err;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
this.send(html);
|
|
294
|
-
if (callback) callback(null, html);
|
|
295
|
-
});
|
|
296
|
-
} else {
|
|
297
|
-
const error = new Error('No template engine configured');
|
|
298
|
-
if (callback) return callback(error);
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return this;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
vary(field) {
|
|
306
|
-
this.append('Vary', field);
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
writeHead() {
|
|
311
|
-
if (this.headersSent) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
this.res.statusCode = this.statusCode;
|
|
316
|
-
|
|
317
|
-
Object.keys(this.headers).forEach(name => {
|
|
318
|
-
this.res.setHeader(name, this.headers[name]);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
this.headersSent = true;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
write(chunk, encoding) {
|
|
325
|
-
if (!this.headersSent) {
|
|
326
|
-
this.writeHead();
|
|
327
|
-
}
|
|
328
|
-
return this.res.write(chunk, encoding);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
end(data, encoding) {
|
|
332
|
-
if (!this.headersSent) {
|
|
333
|
-
this.writeHead();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
this.finished = true;
|
|
337
|
-
this.res.end(data, encoding);
|
|
338
|
-
return this;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
destroy() {
|
|
342
|
-
this.res.destroy();
|
|
343
|
-
return this;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
setTimeout(msecs, callback) {
|
|
347
|
-
this.res.setTimeout(msecs, callback);
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
headersSent() {
|
|
352
|
-
return this.headersSent;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
writableEnded() {
|
|
356
|
-
return this.res.writableEnded;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
writable() {
|
|
360
|
-
return this.res.writable;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
toString() {
|
|
364
|
-
return `Response ${this.statusCode}`;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
toJSON() {
|
|
368
|
-
return {
|
|
369
|
-
statusCode: this.statusCode,
|
|
370
|
-
headers: this.headers,
|
|
371
|
-
finished: this.finished,
|
|
372
|
-
headersSent: this.headersSent
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
module.exports = Response;
|
package/dist/index.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Main entry point for the Spark Web Framework
|
|
5
|
-
* @author Spark Framework Team
|
|
6
|
-
* @since 1.0.0
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const Application = require('./core/application');
|
|
11
|
-
const Router = require('./router/router');
|
|
12
|
-
const Context = require('./core/context');
|
|
13
|
-
|
|
14
|
-
const bodyParser = require('./middleware/body-parser');
|
|
15
|
-
const cors = require('./middleware/cors');
|
|
16
|
-
const compression = require('./middleware/compression');
|
|
17
|
-
const staticFiles = require('./middleware/static');
|
|
18
|
-
const session = require('./middleware/session');
|
|
19
|
-
const rateLimit = require('./middleware/rate-limit');
|
|
20
|
-
const security = require('./middleware/security');
|
|
21
|
-
const healthCheck = require('./middleware/health');
|
|
22
|
-
const metrics = require('./middleware/metrics');
|
|
23
|
-
const logger = require('./middleware/logger');
|
|
24
|
-
|
|
25
|
-
// Error handling utilities
|
|
26
|
-
const { asyncHandler, errorHandler, createError, errors } = require('./utils/async-handler');
|
|
27
|
-
|
|
28
|
-
// Utility classes
|
|
29
|
-
const ContextPool = require('./utils/context-pool');
|
|
30
|
-
const { RegexValidator, SafeRegexCache } = require('./utils/regex-validator');
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Spark Web Framework - A fast, secure, and modern Node.js web framework
|
|
34
|
-
*
|
|
35
|
-
* Spark extends the base Application class to provide a complete web framework
|
|
36
|
-
* with built-in security, middleware support, and modern development features.
|
|
37
|
-
*
|
|
38
|
-
* @class Spark
|
|
39
|
-
* @extends Application
|
|
40
|
-
* @since 1.0.0
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* // Basic usage
|
|
44
|
-
* const { Spark } = require('spark-framework');
|
|
45
|
-
*
|
|
46
|
-
* const app = new Spark({
|
|
47
|
-
* port: 3000,
|
|
48
|
-
* security: {
|
|
49
|
-
* cors: { origin: true },
|
|
50
|
-
* rateLimit: { max: 100, window: 60000 }
|
|
51
|
-
* }
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* app.get('/', (ctx) => {
|
|
55
|
-
* ctx.json({ message: 'Hello Spark!' });
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* app.listen();
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* // With middleware
|
|
62
|
-
* const app = new Spark();
|
|
63
|
-
*
|
|
64
|
-
* app.use(bodyParser.json());
|
|
65
|
-
* app.use(cors({ origin: 'https://example.com' }));
|
|
66
|
-
*
|
|
67
|
-
* app.post('/api/users', (ctx) => {
|
|
68
|
-
* const userData = ctx.body;
|
|
69
|
-
* ctx.json({ success: true, data: userData });
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* app.listen(8080);
|
|
73
|
-
*/
|
|
74
|
-
class Spark extends Application {
|
|
75
|
-
/**
|
|
76
|
-
* Create a new Spark application instance
|
|
77
|
-
*
|
|
78
|
-
* @param {Object} [options={}] - Configuration options for the application
|
|
79
|
-
* @param {number} [options.port=3000] - Port number to listen on
|
|
80
|
-
* @param {string} [options.host='127.0.0.1'] - Host address to bind to
|
|
81
|
-
* @param {boolean} [options.cluster=false] - Enable cluster mode
|
|
82
|
-
* @param {Object} [options.security] - Security configuration
|
|
83
|
-
* @param {Object} [options.https] - HTTPS configuration with key and cert
|
|
84
|
-
*
|
|
85
|
-
* @since 1.0.0
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* const app = new Spark({
|
|
89
|
-
* port: 8080,
|
|
90
|
-
* host: '0.0.0.0',
|
|
91
|
-
* security: {
|
|
92
|
-
* cors: { origin: ['https://example.com'] },
|
|
93
|
-
* rateLimit: { max: 200, window: 60000 }
|
|
94
|
-
* }
|
|
95
|
-
* });
|
|
96
|
-
*/
|
|
97
|
-
constructor(options) {
|
|
98
|
-
super(options);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Export both Spark and App for backwards compatibility
|
|
103
|
-
const App = Spark;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Main exports for the Spark Web Framework
|
|
107
|
-
*
|
|
108
|
-
* @namespace SparkExports
|
|
109
|
-
* @since 1.0.0
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* // ES6 destructuring
|
|
113
|
-
* const { Spark, Router, bodyParser } = require('spark-framework');
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* // CommonJS
|
|
117
|
-
* const Spark = require('spark-framework').Spark;
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* // Access middleware
|
|
121
|
-
* const { middleware } = require('spark-framework');
|
|
122
|
-
* app.use(middleware.bodyParser.json());
|
|
123
|
-
*/
|
|
124
|
-
module.exports = {
|
|
125
|
-
/**
|
|
126
|
-
* Main Spark application class
|
|
127
|
-
* @type {typeof Spark}
|
|
128
|
-
*/
|
|
129
|
-
Spark,
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Backwards compatibility alias for Spark
|
|
133
|
-
* @deprecated Use Spark instead
|
|
134
|
-
* @type {typeof Spark}
|
|
135
|
-
*/
|
|
136
|
-
App, // Deprecated: Use Spark instead
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Base Application class
|
|
140
|
-
* @type {typeof Application}
|
|
141
|
-
*/
|
|
142
|
-
Application,
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Router class for handling routes
|
|
146
|
-
* @type {typeof Router}
|
|
147
|
-
*/
|
|
148
|
-
Router,
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Context class for request/response handling
|
|
152
|
-
* @type {typeof Context}
|
|
153
|
-
*/
|
|
154
|
-
Context,
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Middleware collection
|
|
158
|
-
* @namespace middleware
|
|
159
|
-
* @property {Function} bodyParser - Body parsing middleware
|
|
160
|
-
* @property {Function} cors - CORS middleware
|
|
161
|
-
* @property {Function} compression - Response compression middleware
|
|
162
|
-
* @property {Function} static - Static file serving middleware
|
|
163
|
-
* @property {Function} session - Session management middleware
|
|
164
|
-
* @property {Function} rateLimit - Rate limiting middleware
|
|
165
|
-
* @property {Function} security - Security headers middleware
|
|
166
|
-
* @property {Function} healthCheck - Health check endpoint middleware
|
|
167
|
-
* @property {Function} metrics - Metrics collection middleware
|
|
168
|
-
* @property {Function} logger - Request logging middleware
|
|
169
|
-
*/
|
|
170
|
-
middleware: {
|
|
171
|
-
bodyParser,
|
|
172
|
-
cors,
|
|
173
|
-
compression,
|
|
174
|
-
static: staticFiles,
|
|
175
|
-
session,
|
|
176
|
-
rateLimit,
|
|
177
|
-
security,
|
|
178
|
-
helmet: security.helmet || security, // Alias for security middleware
|
|
179
|
-
healthCheck,
|
|
180
|
-
health: healthCheck, // Alias
|
|
181
|
-
metrics,
|
|
182
|
-
logger,
|
|
183
|
-
cache: require('./middleware/cache'), // Add cache middleware
|
|
184
|
-
compress: compression // Alias for compression
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Body parsing middleware - Direct export
|
|
189
|
-
* @type {Function}
|
|
190
|
-
*/
|
|
191
|
-
bodyParser,
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* CORS middleware - Direct export
|
|
195
|
-
* @type {Function}
|
|
196
|
-
*/
|
|
197
|
-
cors,
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Compression middleware - Direct export
|
|
201
|
-
* @type {Function}
|
|
202
|
-
*/
|
|
203
|
-
compression,
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Static file middleware - Direct export
|
|
207
|
-
* @type {Function}
|
|
208
|
-
*/
|
|
209
|
-
static: staticFiles,
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Session middleware - Direct export
|
|
213
|
-
* @type {Function}
|
|
214
|
-
*/
|
|
215
|
-
session,
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Rate limiting middleware - Direct export
|
|
219
|
-
* @type {Function}
|
|
220
|
-
*/
|
|
221
|
-
rateLimit,
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Security headers middleware - Direct export
|
|
225
|
-
* @type {Function}
|
|
226
|
-
*/
|
|
227
|
-
security,
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Health check middleware - Direct export
|
|
231
|
-
* @type {Function}
|
|
232
|
-
*/
|
|
233
|
-
healthCheck,
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Metrics collection middleware - Direct export
|
|
237
|
-
* @type {Function}
|
|
238
|
-
*/
|
|
239
|
-
metrics,
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Logger middleware - Direct export
|
|
243
|
-
* @type {Function}
|
|
244
|
-
*/
|
|
245
|
-
logger,
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Error handling utilities
|
|
249
|
-
* @namespace errorHandling
|
|
250
|
-
* @property {Function} asyncHandler - Wraps async functions for error handling
|
|
251
|
-
* @property {Function} errorHandler - Global error handler middleware
|
|
252
|
-
* @property {Function} createError - Creates custom errors with status codes
|
|
253
|
-
* @property {Object} errors - Predefined error types
|
|
254
|
-
*/
|
|
255
|
-
errorHandling: {
|
|
256
|
-
asyncHandler,
|
|
257
|
-
errorHandler,
|
|
258
|
-
createError,
|
|
259
|
-
errors
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Utility classes and functions
|
|
264
|
-
* @namespace utils
|
|
265
|
-
* @property {Class} ContextPool - Object pool for Context instances
|
|
266
|
-
* @property {Class} RegexValidator - Regex validation utilities
|
|
267
|
-
* @property {Class} SafeRegexCache - Safe regex caching system
|
|
268
|
-
*/
|
|
269
|
-
utils: {
|
|
270
|
-
ContextPool,
|
|
271
|
-
RegexValidator,
|
|
272
|
-
SafeRegexCache
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Default export for ES6 compatibility
|
|
278
|
-
* @type {Object}
|
|
279
|
-
*/
|
|
280
|
-
module.exports.default = module.exports;
|