kempo-server 2.1.1 → 3.0.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/CONFIG.md +295 -187
- package/README.md +31 -4
- package/SPA.md +14 -14
- package/UTILS.md +39 -0
- package/dist/defaultConfig.js +1 -1
- package/dist/index.js +1 -1
- package/dist/render.js +2 -0
- package/dist/rescan.js +1 -0
- package/dist/router.js +1 -1
- package/dist/serveFile.js +1 -1
- package/dist/templating/index.js +1 -0
- package/dist/templating/parse.js +1 -0
- package/docs/dist/caching.html +324 -0
- package/docs/dist/cli-utils.html +175 -0
- package/docs/dist/configuration.html +414 -0
- package/docs/dist/examples.html +296 -0
- package/docs/dist/fs-utils.html +206 -0
- package/docs/dist/getting-started.html +167 -0
- package/docs/dist/index.html +183 -0
- package/docs/dist/middleware.html +237 -0
- package/docs/dist/request-response.html +200 -0
- package/docs/dist/routing.html +177 -0
- package/docs/dist/templating.html +292 -0
- package/docs/{theme.css → dist/theme.css} +1 -3
- package/docs/src/.config.js +11 -0
- package/docs/{caching.html → src/caching.page.html} +4 -19
- package/docs/{cli-utils.html → src/cli-utils.page.html} +4 -20
- package/docs/{configuration.html → src/configuration.page.html} +4 -18
- package/docs/src/default.template.html +35 -0
- package/docs/{examples.html → src/examples.page.html} +9 -18
- package/docs/{fs-utils.html → src/fs-utils.page.html} +4 -20
- package/docs/{getting-started.html → src/getting-started.page.html} +4 -18
- package/docs/src/index.page.html +79 -0
- package/docs/{middleware.html → src/middleware.page.html} +4 -18
- package/docs/src/nav.fragment.html +73 -0
- package/docs/{request-response.html → src/request-response.page.html} +4 -18
- package/docs/{routing.html → src/routing.page.html} +4 -18
- package/docs/src/templating.page.html +188 -0
- package/{llm.txt → llms.txt} +100 -30
- package/package.json +7 -3
- package/scripts/build.js +19 -11
- package/scripts/render.js +58 -0
- package/src/defaultConfig.js +14 -2
- package/src/index.js +1 -1
- package/src/rescan.js +14 -0
- package/src/router.js +82 -11
- package/src/serveFile.js +27 -0
- package/src/templating/index.js +132 -0
- package/src/templating/parse.js +285 -0
- package/tests/cacheConfig.node-test.js +2 -2
- package/tests/config-flag.node-test.js +61 -25
- package/tests/customRoute-outside-root.node-test.js +1 -1
- package/tests/rescan.node-test.js +69 -0
- package/tests/router-wildcard.node-test.js +47 -2
- package/tests/templating-parse.node-test.js +243 -0
- package/tests/templating-render.node-test.js +188 -0
- package/tests/utils/test-scenario.js +4 -4
- package/docs/.config.json.example +0 -29
- package/docs/api/_admin/cache/DELETE.js +0 -28
- package/docs/api/_admin/cache/GET.js +0 -53
- package/docs/api/user/[id]/GET.js +0 -15
- package/docs/api/user/[id]/[info]/DELETE.js +0 -12
- package/docs/api/user/[id]/[info]/GET.js +0 -17
- package/docs/api/user/[id]/[info]/POST.js +0 -18
- package/docs/api/user/[id]/[info]/PUT.js +0 -19
- package/docs/index.html +0 -88
- package/docs/init.js +0 -0
- package/docs/kempo.min.css +0 -1
- package/docs/nav.inc.html +0 -41
- package/docs/nav.inc.js +0 -16
- /package/docs/{manifest.json → dist/manifest.json} +0 -0
- /package/docs/{media → dist/media}/hexagon.svg +0 -0
- /package/docs/{media → dist/media}/icon-maskable.png +0 -0
- /package/docs/{media → dist/media}/icon.svg +0 -0
- /package/docs/{media → dist/media}/icon128.png +0 -0
- /package/docs/{media → dist/media}/icon144.png +0 -0
- /package/docs/{media → dist/media}/icon152.png +0 -0
- /package/docs/{media → dist/media}/icon16-48.svg +0 -0
- /package/docs/{media → dist/media}/icon16.png +0 -0
- /package/docs/{media → dist/media}/icon192.png +0 -0
- /package/docs/{media → dist/media}/icon256.png +0 -0
- /package/docs/{media → dist/media}/icon32.png +0 -0
- /package/docs/{media → dist/media}/icon384.png +0 -0
- /package/docs/{media → dist/media}/icon48.png +0 -0
- /package/docs/{media → dist/media}/icon512.png +0 -0
- /package/docs/{media → dist/media}/icon64.png +0 -0
- /package/docs/{media → dist/media}/icon72.png +0 -0
- /package/docs/{media → dist/media}/icon96.png +0 -0
- /package/docs/{media → dist/media}/kempo-fist.svg +0 -0
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<meta charset='utf-8'>
|
|
4
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
5
|
-
<title>Configuration - 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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Configuration</h1>
|
|
1
|
+
<page pageName="Configuration" title="Configuration - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Customize Kempo Server's behavior with a simple JSON configuration file.</p>
|
|
16
4
|
|
|
17
5
|
<h2>Configuration File</h2>
|
|
@@ -318,7 +306,5 @@
|
|
|
318
306
|
<li>Enable file watching in development, disable in production for stability</li>
|
|
319
307
|
<li>Use shorter TTL in development for faster iteration</li>
|
|
320
308
|
</ul>
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
</body>
|
|
324
|
-
</html>
|
|
309
|
+
</content>
|
|
310
|
+
</page>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta
|
|
6
|
+
name="viewport"
|
|
7
|
+
content="width=device-width, initial-scale=1.0"
|
|
8
|
+
/>
|
|
9
|
+
<title>{{title}}</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>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<fragment name="nav" />
|
|
25
|
+
<main>
|
|
26
|
+
<h1 class="ta-center">{{pageName}}</h1>
|
|
27
|
+
<location />
|
|
28
|
+
</main>
|
|
29
|
+
<div style="height:25vh"></div>
|
|
30
|
+
<script
|
|
31
|
+
type="module"
|
|
32
|
+
src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"
|
|
33
|
+
></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<meta charset='utf-8'>
|
|
4
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
5
|
-
<title>Examples & Demos - 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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Examples & Demos</h1>
|
|
1
|
+
<page pageName="Examples & Demos" title="Examples & Demos - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Explore practical examples and try interactive demos of Kempo Server features.</p>
|
|
16
4
|
|
|
17
5
|
<h2>Code Examples</h2>
|
|
@@ -129,6 +117,11 @@
|
|
|
129
117
|
<h3>Production Configuration</h3>
|
|
130
118
|
<pre><code class="hljs json">{<br /> <span class="hljs-attr">"allowedMimes"</span>: {<br /> <span class="hljs-attr">"html"</span>: <span class="hljs-string">"text/html"</span>,<br /> <span class="hljs-attr">"css"</span>: <span class="hljs-string">"text/css"</span>,<br /> <span class="hljs-attr">"js"</span>: <span class="hljs-string">"application/javascript"</span>,<br /> <span class="hljs-attr">"json"</span>: <span class="hljs-string">"application/json"</span>,<br /> <span class="hljs-attr">"png"</span>: <span class="hljs-string">"image/png"</span>,<br /> <span class="hljs-attr">"jpg"</span>: <span class="hljs-string">"image/jpeg"</span>,<br /> <span class="hljs-attr">"svg"</span>: <span class="hljs-string">"image/svg+xml"</span>,<br /> <span class="hljs-attr">"woff"</span>: <span class="hljs-string">"font/woff"</span>,<br /> <span class="hljs-attr">"woff2"</span>: <span class="hljs-string">"font/woff2"</span><br /> },<br /> <span class="hljs-attr">"disallowedRegex"</span>: [<br /> <span class="hljs-string">"^/\\..*"</span>,<br /> <span class="hljs-string">"\\.env$"</span>,<br /> <span class="hljs-string">"\\.config$"</span>,<br /> <span class="hljs-string">"password"</span>,<br /> <span class="hljs-string">"secret"</span>,<br /> <span class="hljs-string">"node_modules"</span>,<br /> <span class="hljs-string">"\\.git"</span>,<br /> <span class="hljs-string">"\\.map$"</span><br /> ],<br /> <span class="hljs-attr">"middleware"</span>: {<br /> <span class="hljs-attr">"cors"</span>: {<br /> <span class="hljs-attr">"enabled"</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">"origin"</span>: <span class="hljs-string">"https://yourdomain.com"</span>,<br /> <span class="hljs-attr">"credentials"</span>: <span class="hljs-literal">true</span><br /> },<br /> <span class="hljs-attr">"compression"</span>: {<br /> <span class="hljs-attr">"enabled"</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">"threshold"</span>: <span class="hljs-number">1024</span><br /> },<br /> <span class="hljs-attr">"security"</span>: {<br /> <span class="hljs-attr">"enabled"</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">"headers"</span>: {<br /> <span class="hljs-attr">"X-Content-Type-Options"</span>: <span class="hljs-string">"nosniff"</span>,<br /> <span class="hljs-attr">"X-Frame-Options"</span>: <span class="hljs-string">"DENY"</span>,<br /> <span class="hljs-attr">"X-XSS-Protection"</span>: <span class="hljs-string">"1; mode=block"</span>,<br /> <span class="hljs-attr">"Strict-Transport-Security"</span>: <span class="hljs-string">"max-age=31536000; includeSubDomains"</span><br /> }<br /> },<br /> <span class="hljs-attr">"rateLimit"</span>: {<br /> <span class="hljs-attr">"enabled"</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">"maxRequests"</span>: <span class="hljs-number">100</span>,<br /> <span class="hljs-attr">"windowMs"</span>: <span class="hljs-number">60000</span><br /> },<br /> <span class="hljs-attr">"custom"</span>: [<br /> <span class="hljs-string">"./middleware/auth.js"</span>,<br /> <span class="hljs-string">"./middleware/logging.js"</span>,<br /> <span class="hljs-string">"./middleware/analytics.js"</span><br /> ]<br /> }<br />}</code></pre>
|
|
131
119
|
|
|
120
|
+
<h3>Programmatic File Rescan</h3>
|
|
121
|
+
<p>When your code creates or removes files at runtime (e.g., a CMS generating static pages), you can trigger a file rescan without restarting the server. Import the <code>rescan</code> function from anywhere in the same Node process:</p>
|
|
122
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// api/pages/POST.js</span><br /><span class="hljs-keyword">import</span> { writeFile } <span class="hljs-keyword">from</span> <span class="hljs-string">'fs/promises'</span>;<br /><span class="hljs-keyword">import</span> rescan <span class="hljs-keyword">from</span> <span class="hljs-string">'kempo-server/rescan'</span>;<br /><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">async</span> (req, res) => {<br /> <span class="hljs-keyword">const</span> { slug, html } = req.body;<br /> <span class="hljs-keyword">await</span> writeFile(<span class="hljs-string">`./pages/${slug}.html`</span>, html);<br /> <span class="hljs-keyword">const</span> fileCount = <span class="hljs-keyword">await</span> rescan();<br /> res.json({ published: <span class="hljs-literal">true</span>, fileCount });<br />};</code></pre>
|
|
123
|
+
<p>The <code>rescan()</code> function returns a promise that resolves with the number of files found. It works from route handlers, middleware, file watchers, scheduled tasks, or any other code running in the same Node process.</p>
|
|
124
|
+
|
|
132
125
|
<script>
|
|
133
126
|
async function fetchUser() {
|
|
134
127
|
const userId = document.getElementById('userId').value || 'john';
|
|
@@ -195,7 +188,5 @@
|
|
|
195
188
|
}
|
|
196
189
|
}
|
|
197
190
|
</script>
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
</body>
|
|
201
|
-
</html>
|
|
191
|
+
</content>
|
|
192
|
+
</page>
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
<
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset='utf-8'>
|
|
5
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
6
|
-
<title>File System Utilities - Kempo Server</title>
|
|
7
|
-
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
|
8
|
-
<link rel="icon" type="image/png" sizes="48x48" href="./media/icon48.png">
|
|
9
|
-
<link rel="manifest" href="./manifest.json" />
|
|
10
|
-
<link rel="stylesheet" href="./kempo.min.css" />
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<main>
|
|
14
|
-
<a href="./" class="btn">Home</a>
|
|
15
|
-
<h1>File System Utilities</h1>
|
|
1
|
+
<page pageName="File System Utilities" title="File System Utilities - Kempo Server">
|
|
2
|
+
<content>
|
|
16
3
|
<p>The file system utilities provide common file and directory operations with Promise-based APIs for Node.js applications.</p>
|
|
17
4
|
|
|
18
5
|
<h2>Installation</h2>
|
|
@@ -111,8 +98,5 @@ async function backupProject() {
|
|
|
111
98
|
<li>Functions handle errors appropriately (e.g., ensureDir ignores EEXIST)</li>
|
|
112
99
|
<li>copyDir preserves directory structure recursively</li>
|
|
113
100
|
</ul>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</body>
|
|
117
|
-
</html></content>
|
|
118
|
-
<parameter name="filePath">c:\Users\dusti\dev\kempo-server\docs\fs-utils.html
|
|
101
|
+
</content>
|
|
102
|
+
</page>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<meta charset='utf-8'>
|
|
4
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
5
|
-
<title>Getting Started - 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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Getting Started</h1>
|
|
1
|
+
<page pageName="Getting Started" title="Getting Started - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Get up and running with Kempo Server in just a few steps.</p>
|
|
16
4
|
|
|
17
5
|
<h2>Installation</h2>
|
|
@@ -71,7 +59,5 @@
|
|
|
71
59
|
<li><a href="middleware.html">Middleware</a> - Add authentication, logging, CORS, and more</li>
|
|
72
60
|
<li><a href="examples.html">Examples & Demos</a> - See real-world examples in action</li>
|
|
73
61
|
</ul>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
</body>
|
|
77
|
-
</html>
|
|
62
|
+
</content>
|
|
63
|
+
</page>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<page pageName="Kempo Server" title="Kempo Server">
|
|
2
|
+
<content>
|
|
3
|
+
<div class="ta-center">
|
|
4
|
+
<p class="mb0">
|
|
5
|
+
<a
|
|
6
|
+
href="https://github.com/dustinpoissant/kempo-server"
|
|
7
|
+
class="btn primary mr"
|
|
8
|
+
target="_blank"
|
|
9
|
+
>GitHub</a>
|
|
10
|
+
<a
|
|
11
|
+
href="https://www.npmjs.com/package/kempo-server"
|
|
12
|
+
class="btn"
|
|
13
|
+
target="_blank"
|
|
14
|
+
>NPM</a>
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
<p>A lightweight, zero-dependency, file based routing server.</p>
|
|
18
|
+
|
|
19
|
+
<nav class="b r mb p">
|
|
20
|
+
<div class="row -mx">
|
|
21
|
+
<div class="col m-span-12 d-span-6 px">
|
|
22
|
+
<h4 class="mt0">Getting Started</h4>
|
|
23
|
+
<ul>
|
|
24
|
+
<li><a href="getting-started.html">Getting Started</a></li>
|
|
25
|
+
<li><a href="routing.html">Routing</a></li>
|
|
26
|
+
<li><a href="request-response.html">Request & Response</a></li>
|
|
27
|
+
</ul>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="col m-span-12 d-span-6 px">
|
|
30
|
+
<h4 class="mt0">Advanced Features</h4>
|
|
31
|
+
<ul>
|
|
32
|
+
<li><a href="configuration.html">Configuration</a></li>
|
|
33
|
+
<li><a href="templating.html">Templating</a></li>
|
|
34
|
+
<li><a href="middleware.html">Middleware</a></li>
|
|
35
|
+
<li><a href="caching.html">Module Caching</a></li>
|
|
36
|
+
<li><a href="cli-utils.html">CLI Utilities</a></li>
|
|
37
|
+
<li><a href="fs-utils.html">File System Utilities</a></li>
|
|
38
|
+
<li><a href="examples.html">Examples & Demos</a></li>
|
|
39
|
+
</ul>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</nav>
|
|
43
|
+
|
|
44
|
+
<div class="b r mb p">
|
|
45
|
+
<h3 class="mt0">Quick Start</h3>
|
|
46
|
+
<p>Install and run Kempo Server in seconds:</p>
|
|
47
|
+
<pre><code>npm install kempo-server<br />npx kempo-server --root public</code></pre>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div class="row -mx mb">
|
|
51
|
+
<div class="col m-span-12 d-span-6 px">
|
|
52
|
+
<div class="b r p">
|
|
53
|
+
<h4 class="mt0">Features</h4>
|
|
54
|
+
<ul>
|
|
55
|
+
<li><strong>Zero Dependencies</strong> - No external dependencies</li>
|
|
56
|
+
<li><strong>File-based Routing</strong> - Directory structure defines routes</li>
|
|
57
|
+
<li><strong>Dynamic Routes</strong> - Parameterized routes with [brackets]</li>
|
|
58
|
+
<li><strong>Wildcard Routes</strong> - Map directories with * patterns</li>
|
|
59
|
+
<li><strong>Middleware System</strong> - Authentication, CORS, logging, and more</li>
|
|
60
|
+
<li><strong>Request/Response Objects</strong> - Enhanced request handling</li>
|
|
61
|
+
</ul>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<div class="col m-span-12 d-span-6 px">
|
|
65
|
+
<div class="b r p">
|
|
66
|
+
<h4 class="mt0">Built-in Middleware</h4>
|
|
67
|
+
<ul>
|
|
68
|
+
<li><strong>CORS</strong> - Cross-origin resource sharing</li>
|
|
69
|
+
<li><strong>Compression</strong> - Automatic gzip compression</li>
|
|
70
|
+
<li><strong>Rate Limiting</strong> - Request throttling</li>
|
|
71
|
+
<li><strong>Security Headers</strong> - Security best practices</li>
|
|
72
|
+
<li><strong>Request Logging</strong> - Configurable logging</li>
|
|
73
|
+
<li><strong>Custom Middleware</strong> - Load your own middleware</li>
|
|
74
|
+
</ul>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</content>
|
|
79
|
+
</page>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Middleware</h1>
|
|
1
|
+
<page pageName="Middleware" title="Middleware - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Kempo Server includes a powerful middleware system that allows you to add functionality like authentication, logging, CORS, compression, and more.</p>
|
|
16
4
|
|
|
17
5
|
<h2>How Middleware Works</h2>
|
|
@@ -141,7 +129,5 @@
|
|
|
141
129
|
<li>Cache expensive operations when possible</li>
|
|
142
130
|
<li>Consider the performance impact of middleware order</li>
|
|
143
131
|
</ul>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
</body>
|
|
147
|
-
</html>
|
|
132
|
+
</content>
|
|
133
|
+
</page>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<fragment>
|
|
2
|
+
<k-nav
|
|
3
|
+
fixed
|
|
4
|
+
class="bg-primary"
|
|
5
|
+
>
|
|
6
|
+
<button
|
|
7
|
+
id="toggleNavSideMenu"
|
|
8
|
+
class="link"
|
|
9
|
+
>
|
|
10
|
+
<k-icon name="menu"></k-icon>
|
|
11
|
+
</button>
|
|
12
|
+
<a
|
|
13
|
+
href="./"
|
|
14
|
+
class="d-if ph"
|
|
15
|
+
style="align-items: center"
|
|
16
|
+
>
|
|
17
|
+
<img src="./media/icon32.png" alt="Kempo Server Icon" class="pr" />
|
|
18
|
+
Kempo Server
|
|
19
|
+
</a>
|
|
20
|
+
<div class="flex"></div>
|
|
21
|
+
<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>
|
|
22
|
+
<a href="https://github.com/dustinpoissant/kempo-ui" target="_blank"><k-icon name="github-mark"></k-icont></a>
|
|
23
|
+
<k-theme-switcher></k-theme-switcher>
|
|
24
|
+
</k-nav>
|
|
25
|
+
<div style="width: 100%; height: 4rem;"></div>
|
|
26
|
+
<k-aside
|
|
27
|
+
id="navSideMenu"
|
|
28
|
+
state="offscreen"
|
|
29
|
+
>
|
|
30
|
+
<menu>
|
|
31
|
+
<a href="./" class="ta-center bb mb r0">
|
|
32
|
+
<h1 class="tc-primary">Kempo Server</h1>
|
|
33
|
+
<img src="./media/icon128.png" alt="Kempo UI Icon" />
|
|
34
|
+
</a>
|
|
35
|
+
<h3>Getting Started</h3>
|
|
36
|
+
<a href="./" class="d-b pq pl">Quick Start</a>
|
|
37
|
+
<a href="./routing.html" class="d-b pq pl">Routing</a>
|
|
38
|
+
<a href="./request-response.html" class="d-b pq pl">Request & Response</a>
|
|
39
|
+
<br /><br />
|
|
40
|
+
<h3>Advanced Features</h3>
|
|
41
|
+
<a href="configuration.html" class="d-b pq pl">Configuration</a>
|
|
42
|
+
<a href="templating.html" class="d-b pq pl">Templating</a>
|
|
43
|
+
<a href="middleware.html" class="d-b pq pl">Middleware</a>
|
|
44
|
+
<a href="caching.html" class="d-b pq pl">Module Caching</a>
|
|
45
|
+
<a href="cli-utils.html" class="d-b pq pl">CLI Utilities</a>
|
|
46
|
+
<a href="fs-utils.html" class="d-b pq pl">File System Utilities</a>
|
|
47
|
+
<a href="examples.html" class="d-b pq pl">Examples & Demos</a>
|
|
48
|
+
</menu>
|
|
49
|
+
</k-aside>
|
|
50
|
+
<script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Aside.js" type="module"></script>
|
|
51
|
+
<script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Main.js" type="module"></script>
|
|
52
|
+
<script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Nav.js" type="module"></script>
|
|
53
|
+
<script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/Icon.js" type="module"></script>
|
|
54
|
+
<script src="https://cdn.jsdelivr.net/npm/kempo-ui@0.3.5/src/components/ThemeSwitcher.js" type="module"></script>
|
|
55
|
+
<script>
|
|
56
|
+
document.getElementById('toggleNavSideMenu').addEventListener('click', async () => {
|
|
57
|
+
await window.customElements.whenDefined('k-aside');
|
|
58
|
+
document.getElementById('navSideMenu').toggle();
|
|
59
|
+
});
|
|
60
|
+
document.addEventListener('click', function(e) {
|
|
61
|
+
if (e.target.matches('a[href^="#"]')) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
const targetId = e.target.getAttribute('href').replace('#', '');
|
|
64
|
+
const target = document.getElementById(targetId);
|
|
65
|
+
if (target) {
|
|
66
|
+
target.scrollIntoView({ behavior: 'smooth' });
|
|
67
|
+
const url = window.location.pathname + window.location.search + '#' + targetId;
|
|
68
|
+
history.replaceState(null, '', url);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
</script>
|
|
73
|
+
</fragment>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Request & Response Objects</h1>
|
|
1
|
+
<page pageName="Request & Response Objects" title="Request & Response Objects - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Learn how to work with HTTP requests and responses in Kempo Server.</p>
|
|
16
4
|
|
|
17
5
|
<h2>Request Object</h2>
|
|
@@ -104,7 +92,5 @@
|
|
|
104
92
|
|
|
105
93
|
<h3>Request Validation</h3>
|
|
106
94
|
<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>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
</body>
|
|
110
|
-
</html>
|
|
95
|
+
</content>
|
|
96
|
+
</page>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<meta charset='utf-8'>
|
|
4
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
5
|
-
<title>Routes & Routing - 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="./kempo.min.css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main>
|
|
13
|
-
<a href="./" class="btn">Home</a>
|
|
14
|
-
<h1>Routes & Routing</h1>
|
|
1
|
+
<page pageName="Routing" title="Routing - Kempo Server">
|
|
2
|
+
<content>
|
|
15
3
|
<p>Learn how Kempo Server's file-based routing system works.</p>
|
|
16
4
|
|
|
17
5
|
<h2>How Routes Work</h2>
|
|
@@ -81,7 +69,5 @@
|
|
|
81
69
|
<li><code>index.html</code> / <code>index.htm</code> — served as static</li>
|
|
82
70
|
</ol>
|
|
83
71
|
<p>This applies to both exact and wildcard custom routes. For example, with a wildcard route <code>"/api/**": "../api/**"</code>, a request to <code>/api/auth/session</code> resolves to the <code>../api/auth/session/</code> directory and executes the appropriate route file (e.g. <code>GET.js</code> for GET requests).</p>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
</body>
|
|
87
|
-
</html>
|
|
72
|
+
</content>
|
|
73
|
+
</page>
|