@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.
Files changed (64) hide show
  1. package/CHANGELOG.md +632 -315
  2. package/LICENSE +20 -20
  3. package/README.md +288 -241
  4. package/package.json +83 -89
  5. package/src/core/application.js +1068 -956
  6. package/src/core/context.js +1098 -830
  7. package/src/core/middleware.js +303 -217
  8. package/src/index.js +183 -280
  9. package/src/middleware/body-parser.js +482 -526
  10. package/src/middleware/cache.js +177 -170
  11. package/src/middleware/compression.js +177 -182
  12. package/src/middleware/cors.js +176 -95
  13. package/src/middleware/health.js +219 -218
  14. package/src/middleware/logger.js +195 -194
  15. package/src/middleware/metrics.js +339 -327
  16. package/src/middleware/rate-limit.js +367 -319
  17. package/src/middleware/security.js +442 -332
  18. package/src/middleware/session.js +647 -529
  19. package/src/middleware/static.js +404 -299
  20. package/src/router/layer.js +197 -117
  21. package/src/router/route.js +149 -123
  22. package/src/router/router.js +703 -755
  23. package/src/utils/async-handler.js +145 -147
  24. package/src/utils/context-pool.js +83 -82
  25. package/src/utils/regex-validator.js +187 -163
  26. package/src/utils/safe-json.js +110 -0
  27. package/types/index.d.ts +536 -291
  28. package/dist/LICENSE +0 -21
  29. package/dist/README.md +0 -242
  30. package/dist/core/application.js +0 -959
  31. package/dist/core/context.js +0 -833
  32. package/dist/core/middleware.js +0 -220
  33. package/dist/core/request.js +0 -335
  34. package/dist/core/response.js +0 -377
  35. package/dist/index.js +0 -280
  36. package/dist/middleware/body-parser.js +0 -528
  37. package/dist/middleware/cache.js +0 -173
  38. package/dist/middleware/compression.js +0 -185
  39. package/dist/middleware/cors.js +0 -97
  40. package/dist/middleware/health.js +0 -221
  41. package/dist/middleware/index.js +0 -23
  42. package/dist/middleware/logger.js +0 -197
  43. package/dist/middleware/metrics.js +0 -330
  44. package/dist/middleware/rate-limit.js +0 -322
  45. package/dist/middleware/security.js +0 -335
  46. package/dist/middleware/session.js +0 -532
  47. package/dist/middleware/static.js +0 -301
  48. package/dist/package.json +0 -62
  49. package/dist/router/layer.js +0 -119
  50. package/dist/router/route.js +0 -125
  51. package/dist/router/router.js +0 -758
  52. package/dist/types/index.d.ts +0 -291
  53. package/dist/utils/async-handler.js +0 -150
  54. package/dist/utils/cache.js +0 -443
  55. package/dist/utils/context-pool.js +0 -85
  56. package/dist/utils/error-types.js +0 -134
  57. package/dist/utils/http.js +0 -415
  58. package/dist/utils/regex-validator.js +0 -166
  59. package/src/core/request.js +0 -335
  60. package/src/core/response.js +0 -377
  61. package/src/middleware/index.js +0 -23
  62. package/src/utils/cache.js +0 -443
  63. package/src/utils/error-types.js +0 -134
  64. package/src/utils/http.js +0 -415
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Ersin Koç
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ersin Koç
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,242 +1,289 @@
1
- # ⚡ Spark
2
-
3
- A fast, lightweight, and zero-dependency Node.js web framework built for performance and simplicity.
4
-
5
- [![npm version](https://badge.fury.io/js/@oxog/spark.svg)](https://badge.fury.io/js/@oxog/spark)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](https://nodejs.org/)
8
-
9
- ## 🚀 Features
10
-
11
- - **Zero Dependencies** - No external dependencies, pure Node.js
12
- - **High Performance** - Built for speed with optimized request handling
13
- - **Middleware Support** - Express-like middleware system
14
- - **Advanced Router** - Powerful routing with parameter support
15
- - **Session Management** - Built-in session handling with auto-save
16
- - **Security First** - CORS, CSRF, rate limiting, and security headers
17
- - **TypeScript Support** - Full TypeScript definitions included
18
- - **Memory Efficient** - Optimized for low memory usage
19
- - **Easy to Use** - Simple, intuitive API
20
-
21
- ## 📦 Installation
22
-
23
- ```bash
24
- npm install @oxog/spark
25
- ```
26
-
27
- ## 🌟 Quick Start
28
-
29
- ```javascript
30
- const { Spark } = require('@oxog/spark');
31
-
32
- const app = new Spark();
33
-
34
- app.get('/', (ctx) => {
35
- ctx.json({ message: 'Hello World!' });
36
- });
37
-
38
- app.listen(3000, () => {
39
- console.log('Server running on port 3000');
40
- });
41
- ```
42
-
43
- ## 📚 Documentation
44
-
45
- ### 🎯 **Quick Links**
46
- - **[📖 Complete Documentation](docs/README.md)** - Full documentation index
47
- - **[🚀 Getting Started](docs/getting-started.md)** - Quick start guide
48
- - **[📋 API Reference](docs/api-reference.md)** - Complete API documentation
49
- - **[🔧 Middleware Guide](docs/middleware-guide.md)** - Comprehensive middleware guide
50
-
51
- ### 📈 **Learning Path**
52
- - **[🟢 Beginner Level](docs/beginner/)** - Start here if you're new to Spark
53
- - **[🟡 Intermediate Level](docs/intermediate/)** - Build sophisticated applications
54
- - **[🔴 Expert Level](docs/expert/)** - Master advanced patterns and architecture
55
-
56
- ### 🛡️ **Production Ready**
57
- - **[Security Best Practices](docs/security-best-practices.md)** - Security guidelines
58
- - **[Deployment Guide](docs/deployment.md)** - Production deployment instructions
59
-
60
- ## 🔧 Core Components
61
-
62
- ### Application
63
- The main Spark application class that handles server lifecycle, middleware, and routing.
64
-
65
- ### Router
66
- Advanced routing system with support for parameters, middleware, and nested routes.
67
-
68
- ### Context
69
- Request/response context object with helper methods for common operations.
70
-
71
- ### Middleware
72
- Extensible middleware system with built-in middleware for common tasks.
73
-
74
- ## 🛠️ Built-in Middleware
75
-
76
- - **Body Parser** - Parse JSON, form data, and text
77
- - **CORS** - Cross-origin resource sharing
78
- - **Session** - Session management with auto-save functionality
79
- - **Security** - Security headers and protection
80
- - **Rate Limiting** - Request rate limiting
81
- - **Compression** - Response compression
82
- - **Static Files** - Static file serving
83
- - **Logger** - Request logging
84
- - **Health Check** - Health monitoring endpoints
85
-
86
- ## 📊 Performance
87
-
88
- Spark is designed for high performance with minimal overhead:
89
-
90
- - **~4000 req/sec** on standard hardware
91
- - **<1ms** average response time
92
- - **<50MB** memory footprint
93
- - **Zero** external dependencies
94
-
95
- ## 🏗️ Architecture
96
-
97
- ```
98
- ┌─────────────────┐
99
- │ Application │
100
- ├─────────────────┤
101
- │ Middleware │
102
- ├─────────────────┤
103
- │ Router │
104
- ├─────────────────┤
105
- │ Context │
106
- ├─────────────────┤
107
- │ HTTP Server │
108
- └─────────────────┘
109
- ```
110
-
111
- ## 🔒 Security
112
-
113
- Spark includes built-in security features:
114
-
115
- - CORS protection
116
- - CSRF protection
117
- - Rate limiting
118
- - Security headers
119
- - Input validation
120
- - XSS protection
121
-
122
- ## 🧪 Testing
123
-
124
- ```bash
125
- # Run all tests
126
- npm test
127
-
128
- # Run specific test suites
129
- npm run test:unit
130
- npm run test:integration
131
- npm run test:examples
132
-
133
- # Run performance benchmarks
134
- npm run benchmark
135
- ```
136
-
137
- ## 📈 Examples
138
-
139
- ### Basic API
140
- ```javascript
141
- const { Spark } = require('@oxog/spark');
142
-
143
- const app = new Spark();
144
-
145
- app.get('/users', (ctx) => {
146
- ctx.json([
147
- { id: 1, name: 'John Doe' },
148
- { id: 2, name: 'Jane Smith' }
149
- ]);
150
- });
151
-
152
- app.get('/users/:id', (ctx) => {
153
- const { id } = ctx.params;
154
- ctx.json({ id, name: 'User ' + id });
155
- });
156
-
157
- app.listen(3000);
158
- ```
159
-
160
- ### With Middleware
161
- ```javascript
162
- const { Spark } = require('@oxog/spark');
163
-
164
- const app = new Spark();
165
-
166
- // Global middleware
167
- app.use(require('@oxog/spark/middleware/logger')());
168
- app.use(require('@oxog/spark/middleware/cors')());
169
-
170
- // Route-specific middleware
171
- app.get('/protected',
172
- require('@oxog/spark/middleware/auth'),
173
- (ctx) => {
174
- ctx.json({ message: 'Protected route' });
175
- }
176
- );
177
-
178
- app.listen(3000);
179
- ```
180
-
181
- ### E-commerce API with Sessions
182
- ```javascript
183
- const { Spark, Router } = require('@oxog/spark');
184
-
185
- const app = new Spark();
186
- const api = new Router();
187
-
188
- // Session middleware with auto-save
189
- app.use(require('@oxog/spark/middleware/session')({
190
- secret: 'your-secret-key',
191
- saveUninitialized: true,
192
- cookie: {
193
- maxAge: 24 * 60 * 60 * 1000, // 24 hours
194
- httpOnly: true,
195
- secure: process.env.NODE_ENV === 'production'
196
- }
197
- }));
198
-
199
- // Authentication
200
- api.post('/auth/login', (ctx) => {
201
- const { email, password } = ctx.body;
202
-
203
- if (authenticate(email, password)) {
204
- ctx.session.userId = user.id; // Auto-saved immediately
205
- ctx.json({ success: true });
206
- } else {
207
- ctx.status(401).json({ error: 'Invalid credentials' });
208
- }
209
- });
210
-
211
- // Protected routes
212
- api.get('/orders', requireAuth, (ctx) => {
213
- const orders = getOrdersByUser(ctx.session.userId);
214
- ctx.json({ orders });
215
- });
216
-
217
- app.use('/api', api.routes());
218
- app.listen(3000);
219
- ```
220
-
221
- ## 🤝 Contributing
222
-
223
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
224
-
225
- ## 📄 License
226
-
227
- MIT License - see the [LICENSE](LICENSE) file for details.
228
-
229
- ## 🔗 Links
230
-
231
- - [Documentation](docs/)
232
- - [Examples](examples/)
233
- - [Issues](https://github.com/oxog/spark/issues)
234
- - [Changelog](CHANGELOG.md)
235
-
236
- ## 🌟 Support
237
-
238
- If you find Spark useful, please consider giving it a star on GitHub!
239
-
240
- ---
241
-
1
+ # ⚡ Spark
2
+
3
+ A fast, lightweight, and zero-dependency Node.js web framework built for performance and simplicity.
4
+
5
+ [![npm version](https://badge.fury.io/js/@oxog/spark.svg)](https://badge.fury.io/js/@oxog/spark)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](https://nodejs.org/)
8
+
9
+ ## 🚀 Features
10
+
11
+ - **Zero Dependencies** - No external dependencies, pure Node.js
12
+ - **High Performance** - Built for speed with optimized request handling
13
+ - **Middleware Support** - Express-like middleware system
14
+ - **Advanced Router** - Powerful routing with parameter support
15
+ - **Session Management** - Built-in session handling with auto-save
16
+ - **Security First** - CORS, CSRF, rate limiting, and security headers
17
+ - **TypeScript Support** - Full TypeScript definitions included
18
+ - **Memory Efficient** - Optimized for low memory usage
19
+ - **Easy to Use** - Simple, intuitive API
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Prerequisites
24
+
25
+ - Node.js >= 14.0.0
26
+
27
+ ```bash
28
+ npm install @oxog/spark
29
+ ```
30
+
31
+ ## 🌟 Quick Start
32
+
33
+ ```javascript
34
+ const { Spark } = require('@oxog/spark');
35
+
36
+ const app = new Spark({
37
+ port: 3000,
38
+ host: '0.0.0.0'
39
+ });
40
+
41
+ app.get('/', (ctx) => {
42
+ ctx.json({ message: 'Welcome to Spark!' });
43
+ });
44
+
45
+ app.listen(() => {
46
+ console.log(`Server is running at http://localhost:3000`);
47
+ });
48
+ ```
49
+
50
+ ## 📚 Documentation
51
+
52
+ ### 🎯 **Quick Links**
53
+ - **[📖 Complete Documentation](docs/README.md)** - Full documentation index
54
+ - **[🚀 Getting Started](docs/getting-started.md)** - Quick start guide
55
+ - **[📋 API Reference](docs/api-reference.md)** - Complete API documentation
56
+ - **[🔧 Middleware Guide](docs/middleware-guide.md)** - Comprehensive middleware guide
57
+
58
+ ### 📈 **Learning Path**
59
+ - **[🟢 Beginner Level](docs/beginner/)** - Start here if you're new to Spark
60
+ - **[🟡 Intermediate Level](docs/intermediate/)** - Build sophisticated applications
61
+ - **[🔴 Expert Level](docs/expert/)** - Master advanced patterns and architecture
62
+
63
+ ### 🛡️ **Production Ready**
64
+ - **[Security Best Practices](docs/security-best-practices.md)** - Security guidelines
65
+ - **[Deployment Guide](docs/deployment.md)** - Production deployment instructions
66
+
67
+ ## 🔧 Core Components
68
+
69
+ ### Application
70
+ The main Spark application class that handles server lifecycle, middleware, and routing.
71
+
72
+ ### Router
73
+ Advanced routing system with support for parameters, middleware, and nested routes.
74
+
75
+ ### Context
76
+ Request/response context object with helper methods for common operations.
77
+
78
+ ### Middleware
79
+ Extensible middleware system with built-in middleware for common tasks.
80
+
81
+ ## 🛠️ Built-in Middleware
82
+
83
+ - **Body Parser** - Parse JSON, form data, and text
84
+ - **CORS** - Cross-origin resource sharing
85
+ - **Session** - Session management with auto-save functionality
86
+ - **Security** - Security headers and protection
87
+ - **Rate Limiting** - Request rate limiting
88
+ - **Compression** - Response compression
89
+ - **Static Files** - Static file serving
90
+ - **Logger** - Request logging
91
+ - **Health Check** - Health monitoring endpoints
92
+
93
+ ## 📊 Performance
94
+
95
+ Spark is designed for high performance with minimal overhead:
96
+
97
+ - **~4000 req/sec** on standard hardware
98
+ - **<1ms** average response time
99
+ - **<50MB** memory footprint
100
+ - **Zero** external dependencies
101
+
102
+ ## 🏗️ Architecture
103
+
104
+ ```
105
+ ┌─────────────────┐
106
+ │ Application │
107
+ ├─────────────────┤
108
+ │ Middleware │
109
+ ├─────────────────┤
110
+ │ Router │
111
+ ├─────────────────┤
112
+ │ Context │
113
+ ├─────────────────┤
114
+ │ HTTP Server │
115
+ └─────────────────┘
116
+ ```
117
+
118
+ ## 🔒 Security
119
+
120
+ Security features are middleware you register with `app.use()`; constructor
121
+ options do not enable them.
122
+
123
+ ```javascript
124
+ const { Spark, security, cors, rateLimit, bodyParser, session, static: serveStatic } = require('@oxog/spark');
125
+
126
+ const app = new Spark({ settings: { trustProxy: true } }); // behind a proxy
127
+ app.use(security()); // CSP, HSTS, X-Frame-Options, nosniff, ...
128
+ app.use(cors({ origin: ['https://app.example.com'] })); // whitelist; sends Vary: Origin
129
+ app.use(rateLimit({ max: 100, windowMs: 60000 })); // 429 + Retry-After per client IP
130
+ app.use(bodyParser({ limit: '1mb' })); // 413 above the limit, also for chunked/gzip bodies
131
+ app.use(session({ secret: process.env.SESSION_SECRET }));
132
+ app.use(security.csrf({ secret: process.env.CSRF_SECRET })); // per-client tokens
133
+ app.use(serveStatic('./public')); // blocks ../, %2e%2e%2f, null bytes, dotfiles
134
+
135
+ app.get('/form', (ctx) => ctx.json({ csrfToken: ctx.csrfToken() }));
136
+ ```
137
+
138
+ What is enforced (each item is covered by tests that make real HTTP requests):
139
+
140
+ - **Headers**: `ctx.set()` and cookies reject CR/LF/NUL, so handlers cannot be tricked into header injection
141
+ - **Bodies**: size limits (Content-Length, chunked and decompressed), JSON depth limit, `__proto__` keys dropped
142
+ - **CSRF**: tokens are bound to the client (session or an HttpOnly SameSite=Strict cookie) and only accepted from the `x-csrf-token` header or `_csrf` body field
143
+ - **Redirects**: `ctx.redirect()` refuses other hosts (including `//host` and `/\host`) unless `settings.allowedRedirectDomains` lists them
144
+ - **Errors**: 5xx messages and stack traces are only sent when `NODE_ENV=development`
145
+ - **XSS**: `security.xssProtection()` escapes `ctx.html()` and JSON string values
146
+
147
+ ## 🔄 Streaming and Shutdown
148
+
149
+ ```javascript
150
+ // Stream a response with backpressure (the source is destroyed if the client disconnects)
151
+ app.get('/export', (ctx) => {
152
+ ctx.set('Content-Type', 'text/csv');
153
+ return ctx.stream(fs.createReadStream('export.csv'));
154
+ });
155
+
156
+ // Stop accepting connections, finish in-flight requests, close idle keep-alive
157
+ // sockets, and destroy whatever is still open after `shutdownTimeout` ms (default 10000)
158
+ await app.close();
159
+ ```
160
+
161
+ While listening, the app closes gracefully on SIGTERM/SIGINT (`handleSignals: false`
162
+ to opt out) and exits with code 1 after an uncaught exception
163
+ (`exitOnUncaughtException: false` to opt out). These process listeners are removed by `close()`.
164
+
165
+ ## 🧪 Testing
166
+
167
+ ```bash
168
+ npm test # test suite (real HTTP servers on ephemeral ports)
169
+ npm run test:coverage # with enforced coverage thresholds
170
+ npm run check # lint + typecheck + coverage
171
+ npm run test:package # pack, install and smoke-test the published archive
172
+ npm run benchmark # performance benchmark
173
+ ```
174
+
175
+ ## 📈 Examples
176
+
177
+ ### Basic API
178
+ ```javascript
179
+ const { Spark } = require('@oxog/spark');
180
+
181
+ const app = new Spark();
182
+
183
+ app.get('/users', (ctx) => {
184
+ ctx.json([
185
+ { id: 1, name: 'John Doe' },
186
+ { id: 2, name: 'Jane Smith' }
187
+ ]);
188
+ });
189
+
190
+ app.get('/users/:id', (ctx) => {
191
+ const { id } = ctx.params;
192
+ ctx.json({ id, name: 'User ' + id });
193
+ });
194
+
195
+ app.listen(3000);
196
+ ```
197
+
198
+ ### With Middleware
199
+ ```javascript
200
+ const { Spark, middleware } = require('@oxog/spark');
201
+
202
+ const app = new Spark();
203
+
204
+ // Global middleware
205
+ app.use(middleware.logger());
206
+ app.use(middleware.cors({
207
+ origin: 'https://example.com'
208
+ }));
209
+
210
+ // Route-specific middleware
211
+ const auth = (ctx, next) => {
212
+ const token = ctx.get('Authorization');
213
+ if (!token || token !== 'Bearer valid-token') {
214
+ return ctx.status(401).json({ error: 'Unauthorized' });
215
+ }
216
+ return next();
217
+ };
218
+
219
+ app.get('/protected', auth, (ctx) => {
220
+ ctx.json({ message: 'This is a protected route.' });
221
+ });
222
+
223
+ app.listen(3000);
224
+ ```
225
+
226
+ ### E-commerce API with Sessions
227
+ ```javascript
228
+ const { Spark, Router, bodyParser, session } = require('@oxog/spark');
229
+
230
+ const app = new Spark();
231
+ const api = new Router();
232
+
233
+ app.use(bodyParser());
234
+
235
+ // Session middleware with auto-save
236
+ app.use(session({
237
+ secret: 'your-secret-key',
238
+ saveUninitialized: true,
239
+ cookie: {
240
+ maxAge: 24 * 60 * 60 * 1000, // 24 hours (milliseconds)
241
+ httpOnly: true,
242
+ secure: process.env.NODE_ENV === 'production'
243
+ }
244
+ }));
245
+
246
+ // Authentication
247
+ api.post('/auth/login', (ctx) => {
248
+ const { email, password } = ctx.body;
249
+
250
+ if (authenticate(email, password)) {
251
+ ctx.session.userId = user.id; // Auto-saved immediately
252
+ ctx.json({ success: true });
253
+ } else {
254
+ ctx.status(401).json({ error: 'Invalid credentials' });
255
+ }
256
+ });
257
+
258
+ // Protected routes
259
+ api.get('/orders', requireAuth, (ctx) => {
260
+ const orders = getOrdersByUser(ctx.session.userId);
261
+ ctx.json({ orders });
262
+ });
263
+
264
+ app.use('/api', api.routes());
265
+ app.listen(3000);
266
+ ```
267
+
268
+ ## 🤝 Contributing
269
+
270
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
271
+
272
+ ## 📄 License
273
+
274
+ MIT License - see the [LICENSE](LICENSE) file for details.
275
+
276
+ ## 🔗 Links
277
+
278
+ - [Documentation](docs/)
279
+ - [Examples](examples/)
280
+ - [Issues](https://github.com/ersinkoc/Spark/issues)
281
+ - [Changelog](CHANGELOG.md)
282
+
283
+ ## 🌟 Support
284
+
285
+ If you find Spark useful, please consider giving it a star on GitHub!
286
+
287
+ ---
288
+
242
289
  Built with ❤️ by the Spark team