kempo-server 2.2.0 → 3.0.1

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 (62) hide show
  1. package/CONFIG.md +295 -187
  2. package/README.md +5 -4
  3. package/SPA.md +14 -14
  4. package/dist/defaultConfig.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/render.js +2 -0
  7. package/dist/router.js +1 -1
  8. package/dist/serveFile.js +1 -1
  9. package/dist/templating/index.js +1 -0
  10. package/dist/templating/parse.js +1 -0
  11. package/docs/caching.html +103 -17
  12. package/docs/cli-utils.html +102 -16
  13. package/docs/configuration.html +104 -17
  14. package/docs/examples.html +104 -17
  15. package/docs/fs-utils.html +102 -16
  16. package/docs/getting-started.html +104 -17
  17. package/docs/index.html +176 -81
  18. package/docs/middleware.html +104 -17
  19. package/docs/request-response.html +104 -17
  20. package/docs/routing.html +104 -17
  21. package/docs/templating.html +292 -0
  22. package/docs-src/.config.js +11 -0
  23. package/docs-src/caching.page.html +220 -0
  24. package/docs-src/cli-utils.page.html +71 -0
  25. package/docs-src/configuration.page.html +310 -0
  26. package/docs-src/default.template.html +35 -0
  27. package/docs-src/examples.page.html +192 -0
  28. package/docs-src/fs-utils.page.html +102 -0
  29. package/docs-src/getting-started.page.html +63 -0
  30. package/docs-src/index.page.html +79 -0
  31. package/docs-src/middleware.page.html +133 -0
  32. package/docs-src/nav.fragment.html +73 -0
  33. package/docs-src/request-response.page.html +96 -0
  34. package/docs-src/routing.page.html +73 -0
  35. package/docs-src/templating.page.html +188 -0
  36. package/llms.txt +97 -31
  37. package/package.json +5 -2
  38. package/scripts/build.js +22 -1
  39. package/scripts/render.js +58 -0
  40. package/src/defaultConfig.js +14 -2
  41. package/src/index.js +1 -1
  42. package/src/router.js +69 -10
  43. package/src/serveFile.js +27 -0
  44. package/src/templating/index.js +132 -0
  45. package/src/templating/parse.js +285 -0
  46. package/tests/cacheConfig.node-test.js +2 -2
  47. package/tests/config-flag.node-test.js +61 -25
  48. package/tests/customRoute-outside-root.node-test.js +1 -1
  49. package/tests/router-wildcard.node-test.js +47 -2
  50. package/tests/templating-parse.node-test.js +243 -0
  51. package/tests/templating-render.node-test.js +188 -0
  52. package/tests/utils/test-scenario.js +4 -4
  53. package/docs/.config.json.example +0 -29
  54. package/docs/api/_admin/cache/DELETE.js +0 -28
  55. package/docs/api/_admin/cache/GET.js +0 -53
  56. package/docs/api/user/[id]/GET.js +0 -15
  57. package/docs/api/user/[id]/[info]/DELETE.js +0 -12
  58. package/docs/api/user/[id]/[info]/GET.js +0 -17
  59. package/docs/api/user/[id]/[info]/POST.js +0 -18
  60. package/docs/api/user/[id]/[info]/PUT.js +0 -19
  61. package/docs/init.js +0 -2
  62. package/docs/nav.inc.html +0 -70
package/docs/index.html CHANGED
@@ -1,88 +1,183 @@
1
- <html lang="en" theme="auto">
1
+ <!DOCTYPE html>
2
+ <html lang="en">
2
3
  <head>
3
- <meta charset='utf-8'>
4
- <meta http-equiv='X-UA-Compatible' content='IE=edge'>
5
- <title>Kempo Server - Documentation</title>
6
- <meta name='viewport' content='width=device-width, initial-scale=1'>
7
- <link rel="icon" type="image/png" sizes="48x48" href="./media/icon48.png">
8
- <link rel="manifest" href="./manifest.json" />
9
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kempo-css@2.1.3/dist/kempo.min.css" />
10
- <link rel="stylesheet" href="./theme.css" />
11
- <script src="./init.js"></script>
4
+ <meta charset="UTF-8" />
5
+ <meta
6
+ name="viewport"
7
+ content="width=device-width, initial-scale=1.0"
8
+ />
9
+ <title>Kempo Server</title>
10
+ <link rel="icon" type="image/svg+xml" href="./media/icon.svg" />
11
+ <link rel="icon" type="image/png" sizes="32x32" href="./media/icon32.png" />
12
+ <link rel="manifest" href="./manifest.json" />
13
+ <link
14
+ rel="stylesheet"
15
+ href="https://cdn.jsdelivr.net/npm/kempo-css@2/dist/kempo.min.css"
16
+ />
17
+ <link rel="stylesheet" href="./theme.css" />
18
+ <script>
19
+ window.litDisableBundleWarning = true;
20
+ window.kempo = { pathsToIcons: ['https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/icons/'] };
21
+ </script>
12
22
  </head>
13
23
  <body>
14
- <k-import src="./nav.inc.html"></k-import>
15
- <main>
16
- <h1 class="ta-center">Kempo Server</h1>
17
- <div class="ta-center">
18
- <p class="mb0">
19
- <a href="https://github.com/dustinpoissant/kempo-server" class="btn primary mr" target="_blank">GitHub</a>
20
- <a href="https://www.npmjs.com/package/kempo-server" class="btn" target="_blank">NPM</a>
21
- </p>
22
- </div>
23
- <p>A lightweight, zero-dependency, file based routing server.</p>
24
+
25
+ <k-nav
26
+ fixed
27
+ class="bg-primary"
28
+ >
29
+ <button
30
+ id="toggleNavSideMenu"
31
+ class="link"
32
+ >
33
+ <k-icon name="menu"></k-icon>
34
+ </button>
35
+ <a
36
+ href="./"
37
+ class="d-if ph"
38
+ style="align-items: center"
39
+ >
40
+ <img src="./media/icon32.png" alt="Kempo Server Icon" class="pr" />
41
+ Kempo Server
42
+ </a>
43
+ <div class="flex"></div>
44
+ <a href="https://github.com/dustinpoissant/kempo-ui?tab=License-1-ov-file#creative-commons-attribution-noncommercial-sharealike-20" target="_blank"><k-icon name="license"></k-icont></a>
45
+ <a href="https://github.com/dustinpoissant/kempo-ui" target="_blank"><k-icon name="github-mark"></k-icont></a>
46
+ <k-theme-switcher></k-theme-switcher>
47
+ </k-nav>
48
+ <div style="width: 100%; height: 4rem;"></div>
49
+ <k-aside
50
+ id="navSideMenu"
51
+ state="offscreen"
52
+ >
53
+ <menu>
54
+ <a href="./" class="ta-center bb mb r0">
55
+ <h1 class="tc-primary">Kempo Server</h1>
56
+ <img src="./media/icon128.png" alt="Kempo UI Icon" />
57
+ </a>
58
+ <h3>Getting Started</h3>
59
+ <a href="./" class="d-b pq pl">Quick Start</a>
60
+ <a href="./routing.html" class="d-b pq pl">Routing</a>
61
+ <a href="./request-response.html" class="d-b pq pl">Request & Response</a>
62
+ <br /><br />
63
+ <h3>Advanced Features</h3>
64
+ <a href="configuration.html" class="d-b pq pl">Configuration</a>
65
+ <a href="templating.html" class="d-b pq pl">Templating</a>
66
+ <a href="middleware.html" class="d-b pq pl">Middleware</a>
67
+ <a href="caching.html" class="d-b pq pl">Module Caching</a>
68
+ <a href="cli-utils.html" class="d-b pq pl">CLI Utilities</a>
69
+ <a href="fs-utils.html" class="d-b pq pl">File System Utilities</a>
70
+ <a href="examples.html" class="d-b pq pl">Examples & Demos</a>
71
+ </menu>
72
+ </k-aside>
73
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Aside.js" type="module"></script>
74
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Main.js" type="module"></script>
75
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Nav.js" type="module"></script>
76
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Icon.js" type="module"></script>
77
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/ThemeSwitcher.js" type="module"></script>
78
+ <script>
79
+ document.getElementById('toggleNavSideMenu').addEventListener('click', async () => {
80
+ await window.customElements.whenDefined('k-aside');
81
+ document.getElementById('navSideMenu').toggle();
82
+ });
83
+ document.addEventListener('click', function(e) {
84
+ if (e.target.matches('a[href^="#"]')) {
85
+ e.preventDefault();
86
+ const targetId = e.target.getAttribute('href').replace('#', '');
87
+ const target = document.getElementById(targetId);
88
+ if (target) {
89
+ target.scrollIntoView({ behavior: 'smooth' });
90
+ const url = window.location.pathname + window.location.search + '#' + targetId;
91
+ history.replaceState(null, '', url);
92
+ }
93
+ }
94
+ });
95
+ </script>
24
96
 
25
- <nav class="b r mb p">
26
- <div class="row -mx">
27
- <div class="col m-span-12 d-span-6 px">
28
- <h4 class="mt0">Getting Started</h4>
29
- <ul>
30
- <li><a href="getting-started.html">Getting Started</a></li>
31
- <li><a href="routing.html">Routing</a></li>
32
- <li><a href="request-response.html">Request & Response</a></li>
33
- </ul>
34
- </div>
35
- <div class="col m-span-12 d-span-6 px">
36
- <h4 class="mt0">Advanced Features</h4>
37
- <ul>
38
- <li><a href="configuration.html">Configuration</a></li>
39
- <li><a href="middleware.html">Middleware</a></li>
40
- <li><a href="caching.html">Module Caching</a></li>
41
- <li><a href="cli-utils.html">CLI Utilities</a></li>
42
- <li><a href="fs-utils.html">File System Utilities</a></li>
43
- <li><a href="examples.html">Examples & Demos</a></li>
44
- </ul>
45
- </div>
46
- </div>
47
- </nav>
97
+ <main>
98
+ <h1 class="ta-center">Kempo Server</h1>
99
+
100
+ <div class="ta-center">
101
+ <p class="mb0">
102
+ <a
103
+ href="https://github.com/dustinpoissant/kempo-server"
104
+ class="btn primary mr"
105
+ target="_blank"
106
+ >GitHub</a>
107
+ <a
108
+ href="https://www.npmjs.com/package/kempo-server"
109
+ class="btn"
110
+ target="_blank"
111
+ >NPM</a>
112
+ </p>
113
+ </div>
114
+ <p>A lightweight, zero-dependency, file based routing server.</p>
48
115
 
49
- <div class="b r mb p">
50
- <h3 class="mt0">Quick Start</h3>
51
- <p>Install and run Kempo Server in seconds:</p>
52
- <pre><code>npm install kempo-server
53
- npx kempo-server --root public</code></pre>
54
- </div>
116
+ <nav class="b r mb p">
117
+ <div class="row -mx">
118
+ <div class="col m-span-12 d-span-6 px">
119
+ <h4 class="mt0">Getting Started</h4>
120
+ <ul>
121
+ <li><a href="getting-started.html">Getting Started</a></li>
122
+ <li><a href="routing.html">Routing</a></li>
123
+ <li><a href="request-response.html">Request & Response</a></li>
124
+ </ul>
125
+ </div>
126
+ <div class="col m-span-12 d-span-6 px">
127
+ <h4 class="mt0">Advanced Features</h4>
128
+ <ul>
129
+ <li><a href="configuration.html">Configuration</a></li>
130
+ <li><a href="templating.html">Templating</a></li>
131
+ <li><a href="middleware.html">Middleware</a></li>
132
+ <li><a href="caching.html">Module Caching</a></li>
133
+ <li><a href="cli-utils.html">CLI Utilities</a></li>
134
+ <li><a href="fs-utils.html">File System Utilities</a></li>
135
+ <li><a href="examples.html">Examples & Demos</a></li>
136
+ </ul>
137
+ </div>
138
+ </div>
139
+ </nav>
55
140
 
56
- <div class="row -mx mb">
57
- <div class="col m-span-12 d-span-6 px">
58
- <div class="b r p">
59
- <h4 class="mt0">Features</h4>
60
- <ul>
61
- <li><strong>Zero Dependencies</strong> - No external dependencies</li>
62
- <li><strong>File-based Routing</strong> - Directory structure defines routes</li>
63
- <li><strong>Dynamic Routes</strong> - Parameterized routes with [brackets]</li>
64
- <li><strong>Wildcard Routes</strong> - Map directories with * patterns</li>
65
- <li><strong>Middleware System</strong> - Authentication, CORS, logging, and more</li>
66
- <li><strong>Request/Response Objects</strong> - Enhanced request handling</li>
67
- </ul>
68
- </div>
69
- </div>
70
- <div class="col m-span-12 d-span-6 px">
71
- <div class="b r p">
72
- <h4 class="mt0">Built-in Middleware</h4>
73
- <ul>
74
- <li><strong>CORS</strong> - Cross-origin resource sharing</li>
75
- <li><strong>Compression</strong> - Automatic gzip compression</li>
76
- <li><strong>Rate Limiting</strong> - Request throttling</li>
77
- <li><strong>Security Headers</strong> - Security best practices</li>
78
- <li><strong>Request Logging</strong> - Configurable logging</li>
79
- <li><strong>Custom Middleware</strong> - Load your own middleware</li>
80
- </ul>
81
- </div>
82
- </div>
83
- </div>
84
- </main>
85
- <div style="height:25vh"></div>
86
- <script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
141
+ <div class="b r mb p">
142
+ <h3 class="mt0">Quick Start</h3>
143
+ <p>Install and run Kempo Server in seconds:</p>
144
+ <pre><code>npm install kempo-server<br />npx kempo-server --root public</code></pre>
145
+ </div>
146
+
147
+ <div class="row -mx mb">
148
+ <div class="col m-span-12 d-span-6 px">
149
+ <div class="b r p">
150
+ <h4 class="mt0">Features</h4>
151
+ <ul>
152
+ <li><strong>Zero Dependencies</strong> - No external dependencies</li>
153
+ <li><strong>File-based Routing</strong> - Directory structure defines routes</li>
154
+ <li><strong>Dynamic Routes</strong> - Parameterized routes with [brackets]</li>
155
+ <li><strong>Wildcard Routes</strong> - Map directories with * patterns</li>
156
+ <li><strong>Middleware System</strong> - Authentication, CORS, logging, and more</li>
157
+ <li><strong>Request/Response Objects</strong> - Enhanced request handling</li>
158
+ </ul>
159
+ </div>
160
+ </div>
161
+ <div class="col m-span-12 d-span-6 px">
162
+ <div class="b r p">
163
+ <h4 class="mt0">Built-in Middleware</h4>
164
+ <ul>
165
+ <li><strong>CORS</strong> - Cross-origin resource sharing</li>
166
+ <li><strong>Compression</strong> - Automatic gzip compression</li>
167
+ <li><strong>Rate Limiting</strong> - Request throttling</li>
168
+ <li><strong>Security Headers</strong> - Security best practices</li>
169
+ <li><strong>Request Logging</strong> - Configurable logging</li>
170
+ <li><strong>Custom Middleware</strong> - Load your own middleware</li>
171
+ </ul>
172
+ </div>
173
+ </div>
174
+ </div>
175
+
176
+ </main>
177
+ <div style="height:25vh"></div>
178
+ <script
179
+ type="module"
180
+ src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"
181
+ ></script>
87
182
  </body>
88
- </html>
183
+ </html>
@@ -1,19 +1,102 @@
1
- <html lang="en" theme="auto">
1
+ <!DOCTYPE html>
2
+ <html lang="en">
2
3
  <head>
3
- <meta charset='utf-8'>
4
- <meta http-equiv='X-UA-Compatible' content='IE=edge'>
5
- <title>Middleware - Kempo Server</title>
6
- <meta name='viewport' content='width=device-width, initial-scale=1'>
7
- <link rel="icon" type="image/png" sizes="48x48" href="./media/icon48.png">
8
- <link rel="manifest" href="./manifest.json" />
9
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kempo-css@2.1.3/dist/kempo.min.css" />
10
- <link rel="stylesheet" href="./theme.css" />
11
- <script src="./init.js"></script>
4
+ <meta charset="UTF-8" />
5
+ <meta
6
+ name="viewport"
7
+ content="width=device-width, initial-scale=1.0"
8
+ />
9
+ <title>Middleware - Kempo Server</title>
10
+ <link rel="icon" type="image/svg+xml" href="./media/icon.svg" />
11
+ <link rel="icon" type="image/png" sizes="32x32" href="./media/icon32.png" />
12
+ <link rel="manifest" href="./manifest.json" />
13
+ <link
14
+ rel="stylesheet"
15
+ href="https://cdn.jsdelivr.net/npm/kempo-css@2/dist/kempo.min.css"
16
+ />
17
+ <link rel="stylesheet" href="./theme.css" />
18
+ <script>
19
+ window.litDisableBundleWarning = true;
20
+ window.kempo = { pathsToIcons: ['https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/icons/'] };
21
+ </script>
12
22
  </head>
13
23
  <body>
14
- <k-import src="./nav.inc.html"></k-import>
15
- <k-main>
16
- <h1>Middleware</h1>
24
+
25
+ <k-nav
26
+ fixed
27
+ class="bg-primary"
28
+ >
29
+ <button
30
+ id="toggleNavSideMenu"
31
+ class="link"
32
+ >
33
+ <k-icon name="menu"></k-icon>
34
+ </button>
35
+ <a
36
+ href="./"
37
+ class="d-if ph"
38
+ style="align-items: center"
39
+ >
40
+ <img src="./media/icon32.png" alt="Kempo Server Icon" class="pr" />
41
+ Kempo Server
42
+ </a>
43
+ <div class="flex"></div>
44
+ <a href="https://github.com/dustinpoissant/kempo-ui?tab=License-1-ov-file#creative-commons-attribution-noncommercial-sharealike-20" target="_blank"><k-icon name="license"></k-icont></a>
45
+ <a href="https://github.com/dustinpoissant/kempo-ui" target="_blank"><k-icon name="github-mark"></k-icont></a>
46
+ <k-theme-switcher></k-theme-switcher>
47
+ </k-nav>
48
+ <div style="width: 100%; height: 4rem;"></div>
49
+ <k-aside
50
+ id="navSideMenu"
51
+ state="offscreen"
52
+ >
53
+ <menu>
54
+ <a href="./" class="ta-center bb mb r0">
55
+ <h1 class="tc-primary">Kempo Server</h1>
56
+ <img src="./media/icon128.png" alt="Kempo UI Icon" />
57
+ </a>
58
+ <h3>Getting Started</h3>
59
+ <a href="./" class="d-b pq pl">Quick Start</a>
60
+ <a href="./routing.html" class="d-b pq pl">Routing</a>
61
+ <a href="./request-response.html" class="d-b pq pl">Request & Response</a>
62
+ <br /><br />
63
+ <h3>Advanced Features</h3>
64
+ <a href="configuration.html" class="d-b pq pl">Configuration</a>
65
+ <a href="templating.html" class="d-b pq pl">Templating</a>
66
+ <a href="middleware.html" class="d-b pq pl">Middleware</a>
67
+ <a href="caching.html" class="d-b pq pl">Module Caching</a>
68
+ <a href="cli-utils.html" class="d-b pq pl">CLI Utilities</a>
69
+ <a href="fs-utils.html" class="d-b pq pl">File System Utilities</a>
70
+ <a href="examples.html" class="d-b pq pl">Examples & Demos</a>
71
+ </menu>
72
+ </k-aside>
73
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Aside.js" type="module"></script>
74
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Main.js" type="module"></script>
75
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Nav.js" type="module"></script>
76
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Icon.js" type="module"></script>
77
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/ThemeSwitcher.js" type="module"></script>
78
+ <script>
79
+ document.getElementById('toggleNavSideMenu').addEventListener('click', async () => {
80
+ await window.customElements.whenDefined('k-aside');
81
+ document.getElementById('navSideMenu').toggle();
82
+ });
83
+ document.addEventListener('click', function(e) {
84
+ if (e.target.matches('a[href^="#"]')) {
85
+ e.preventDefault();
86
+ const targetId = e.target.getAttribute('href').replace('#', '');
87
+ const target = document.getElementById(targetId);
88
+ if (target) {
89
+ target.scrollIntoView({ behavior: 'smooth' });
90
+ const url = window.location.pathname + window.location.search + '#' + targetId;
91
+ history.replaceState(null, '', url);
92
+ }
93
+ }
94
+ });
95
+ </script>
96
+
97
+ <main>
98
+ <h1 class="ta-center">Middleware</h1>
99
+
17
100
  <p>Kempo Server includes a powerful middleware system that allows you to add functionality like authentication, logging, CORS, compression, and more.</p>
18
101
 
19
102
  <h2>How Middleware Works</h2>
@@ -143,8 +226,12 @@
143
226
  <li>Cache expensive operations when possible</li>
144
227
  <li>Consider the performance impact of middleware order</li>
145
228
  </ul>
146
- </k-main>
147
- <div style="height:25vh"></div>
148
- <script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
229
+
230
+ </main>
231
+ <div style="height:25vh"></div>
232
+ <script
233
+ type="module"
234
+ src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"
235
+ ></script>
149
236
  </body>
150
- </html>
237
+ </html>
@@ -1,19 +1,102 @@
1
- <html lang="en" theme="auto">
1
+ <!DOCTYPE html>
2
+ <html lang="en">
2
3
  <head>
3
- <meta charset='utf-8'>
4
- <meta http-equiv='X-UA-Compatible' content='IE=edge'>
5
- <title>Request & Response - Kempo Server</title>
6
- <meta name='viewport' content='width=device-width, initial-scale=1'>
7
- <link rel="icon" type="image/png" sizes="48x48" href="./media/icon48.png">
8
- <link rel="manifest" href="./manifest.json" />
9
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kempo-css@2.1.3/dist/kempo.min.css" />
10
- <link rel="stylesheet" href="./theme.css" />
11
- <script src="./init.js"></script>
4
+ <meta charset="UTF-8" />
5
+ <meta
6
+ name="viewport"
7
+ content="width=device-width, initial-scale=1.0"
8
+ />
9
+ <title>Request &amp; Response Objects - Kempo Server</title>
10
+ <link rel="icon" type="image/svg+xml" href="./media/icon.svg" />
11
+ <link rel="icon" type="image/png" sizes="32x32" href="./media/icon32.png" />
12
+ <link rel="manifest" href="./manifest.json" />
13
+ <link
14
+ rel="stylesheet"
15
+ href="https://cdn.jsdelivr.net/npm/kempo-css@2/dist/kempo.min.css"
16
+ />
17
+ <link rel="stylesheet" href="./theme.css" />
18
+ <script>
19
+ window.litDisableBundleWarning = true;
20
+ window.kempo = { pathsToIcons: ['https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/icons/'] };
21
+ </script>
12
22
  </head>
13
23
  <body>
14
- <k-import src="./nav.inc.html"></k-import>
15
- <k-main>
16
- <h1>Request & Response Objects</h1>
24
+
25
+ <k-nav
26
+ fixed
27
+ class="bg-primary"
28
+ >
29
+ <button
30
+ id="toggleNavSideMenu"
31
+ class="link"
32
+ >
33
+ <k-icon name="menu"></k-icon>
34
+ </button>
35
+ <a
36
+ href="./"
37
+ class="d-if ph"
38
+ style="align-items: center"
39
+ >
40
+ <img src="./media/icon32.png" alt="Kempo Server Icon" class="pr" />
41
+ Kempo Server
42
+ </a>
43
+ <div class="flex"></div>
44
+ <a href="https://github.com/dustinpoissant/kempo-ui?tab=License-1-ov-file#creative-commons-attribution-noncommercial-sharealike-20" target="_blank"><k-icon name="license"></k-icont></a>
45
+ <a href="https://github.com/dustinpoissant/kempo-ui" target="_blank"><k-icon name="github-mark"></k-icont></a>
46
+ <k-theme-switcher></k-theme-switcher>
47
+ </k-nav>
48
+ <div style="width: 100%; height: 4rem;"></div>
49
+ <k-aside
50
+ id="navSideMenu"
51
+ state="offscreen"
52
+ >
53
+ <menu>
54
+ <a href="./" class="ta-center bb mb r0">
55
+ <h1 class="tc-primary">Kempo Server</h1>
56
+ <img src="./media/icon128.png" alt="Kempo UI Icon" />
57
+ </a>
58
+ <h3>Getting Started</h3>
59
+ <a href="./" class="d-b pq pl">Quick Start</a>
60
+ <a href="./routing.html" class="d-b pq pl">Routing</a>
61
+ <a href="./request-response.html" class="d-b pq pl">Request & Response</a>
62
+ <br /><br />
63
+ <h3>Advanced Features</h3>
64
+ <a href="configuration.html" class="d-b pq pl">Configuration</a>
65
+ <a href="templating.html" class="d-b pq pl">Templating</a>
66
+ <a href="middleware.html" class="d-b pq pl">Middleware</a>
67
+ <a href="caching.html" class="d-b pq pl">Module Caching</a>
68
+ <a href="cli-utils.html" class="d-b pq pl">CLI Utilities</a>
69
+ <a href="fs-utils.html" class="d-b pq pl">File System Utilities</a>
70
+ <a href="examples.html" class="d-b pq pl">Examples & Demos</a>
71
+ </menu>
72
+ </k-aside>
73
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Aside.js" type="module"></script>
74
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Main.js" type="module"></script>
75
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Nav.js" type="module"></script>
76
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Icon.js" type="module"></script>
77
+ <script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/ThemeSwitcher.js" type="module"></script>
78
+ <script>
79
+ document.getElementById('toggleNavSideMenu').addEventListener('click', async () => {
80
+ await window.customElements.whenDefined('k-aside');
81
+ document.getElementById('navSideMenu').toggle();
82
+ });
83
+ document.addEventListener('click', function(e) {
84
+ if (e.target.matches('a[href^="#"]')) {
85
+ e.preventDefault();
86
+ const targetId = e.target.getAttribute('href').replace('#', '');
87
+ const target = document.getElementById(targetId);
88
+ if (target) {
89
+ target.scrollIntoView({ behavior: 'smooth' });
90
+ const url = window.location.pathname + window.location.search + '#' + targetId;
91
+ history.replaceState(null, '', url);
92
+ }
93
+ }
94
+ });
95
+ </script>
96
+
97
+ <main>
98
+ <h1 class="ta-center">Request &amp; Response Objects</h1>
99
+
17
100
  <p>Learn how to work with HTTP requests and responses in Kempo Server.</p>
18
101
 
19
102
  <h2>Request Object</h2>
@@ -106,8 +189,12 @@
106
189
 
107
190
  <h3>Request Validation</h3>
108
191
  <pre><code class="hljs javascript"><span class="hljs-comment">// api/user/POST.js</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">request, response</span>) </span>{<br /> <span class="hljs-keyword">try</span> {<br /> <span class="hljs-keyword">const</span> userData = <span class="hljs-keyword">await</span> request.json();<br /> <br /> <span class="hljs-comment">// Validate required fields</span><br /> <span class="hljs-keyword">const</span> requiredFields = [<span class="hljs-string">'name'</span>, <span class="hljs-string">'email'</span>, <span class="hljs-string">'password'</span>];<br /> <span class="hljs-keyword">const</span> missingFields = requiredFields.filter(<span class="hljs-function"><span class="hljs-params">field</span> =></span> !userData[field]);<br /> <br /> <span class="hljs-keyword">if</span> (missingFields.length > <span class="hljs-number">0</span>) {<br /> <span class="hljs-keyword">return</span> response.status(<span class="hljs-number">400</span>).json({<br /> error: <span class="hljs-string">'Missing required fields'</span>,<br /> missingFields<br /> });<br /> }<br /> <br /> <span class="hljs-comment">// Validate email format</span><br /> <span class="hljs-keyword">const</span> emailRegex = <span class="hljs-regexp">/^[^\s@]+@[^\s@]+\.[^\s@]+$/</span>;<br /> <span class="hljs-keyword">if</span> (!emailRegex.test(userData.email)) {<br /> <span class="hljs-keyword">return</span> response.status(<span class="hljs-number">400</span>).json({<br /> error: <span class="hljs-string">'Invalid email format'</span><br /> });<br /> }<br /> <br /> <span class="hljs-comment">// Create user</span><br /> <span class="hljs-keyword">const</span> newUser = <span class="hljs-keyword">await</span> createUser(userData);<br /> <br /> response.status(<span class="hljs-number">201</span>).json({<br /> message: <span class="hljs-string">'User created successfully'</span>,<br /> user: {<br /> id: newUser.id,<br /> name: newUser.name,<br /> email: newUser.email<br /> }<br /> });<br /> } <span class="hljs-keyword">catch</span> (error) {<br /> response.status(<span class="hljs-number">400</span>).json({ error: <span class="hljs-string">'Invalid request data'</span> });<br /> }<br />}</code></pre>
109
- </k-main>
110
- <div style="height:25vh"></div><div style="height:25vh"></div>
111
- <script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
192
+
193
+ </main>
194
+ <div style="height:25vh"></div>
195
+ <script
196
+ type="module"
197
+ src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"
198
+ ></script>
112
199
  </body>
113
- </html>
200
+ </html>