kempo-server 2.2.0 → 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 +5 -4
- package/SPA.md +14 -14
- package/dist/defaultConfig.js +1 -1
- package/dist/index.js +1 -1
- package/dist/render.js +2 -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/src/.config.js +11 -0
- package/docs/{caching.html → src/caching.page.html} +4 -22
- package/docs/{cli-utils.html → src/cli-utils.page.html} +4 -22
- package/docs/{configuration.html → src/configuration.page.html} +4 -21
- package/docs/src/default.template.html +35 -0
- package/docs/{examples.html → src/examples.page.html} +4 -21
- package/docs/{fs-utils.html → src/fs-utils.page.html} +4 -22
- package/docs/{getting-started.html → src/getting-started.page.html} +4 -21
- package/docs/src/index.page.html +79 -0
- package/docs/{middleware.html → src/middleware.page.html} +4 -21
- package/docs/src/nav.fragment.html +73 -0
- package/docs/{request-response.html → src/request-response.page.html} +4 -21
- package/docs/{routing.html → src/routing.page.html} +4 -21
- package/docs/src/templating.page.html +188 -0
- package/llms.txt +97 -31
- package/package.json +6 -3
- package/scripts/build.js +22 -1
- package/scripts/render.js +58 -0
- package/src/defaultConfig.js +14 -2
- package/src/index.js +1 -1
- package/src/router.js +69 -10
- 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/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 -2
- package/docs/nav.inc.html +0 -70
- /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
- /package/docs/{theme.css → dist/theme.css} +0 -0
|
@@ -1,19 +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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Configuration</h1>
|
|
1
|
+
<page pageName="Configuration" title="Configuration - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Customize Kempo Server's behavior with a simple JSON configuration file.</p>
|
|
18
4
|
|
|
19
5
|
<h2>Configuration File</h2>
|
|
@@ -320,8 +306,5 @@
|
|
|
320
306
|
<li>Enable file watching in development, disable in production for stability</li>
|
|
321
307
|
<li>Use shorter TTL in development for faster iteration</li>
|
|
322
308
|
</ul>
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
326
|
-
</body>
|
|
327
|
-
</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,19 +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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Examples & Demos</h1>
|
|
1
|
+
<page pageName="Examples & Demos" title="Examples & Demos - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Explore practical examples and try interactive demos of Kempo Server features.</p>
|
|
18
4
|
|
|
19
5
|
<h2>Code Examples</h2>
|
|
@@ -202,8 +188,5 @@
|
|
|
202
188
|
}
|
|
203
189
|
}
|
|
204
190
|
</script>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
208
|
-
</body>
|
|
209
|
-
</html>
|
|
191
|
+
</content>
|
|
192
|
+
</page>
|
|
@@ -1,20 +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="https://cdn.jsdelivr.net/npm/kempo-css@2.1.3/dist/kempo.min.css" />
|
|
11
|
-
<link rel="stylesheet" href="./theme.css" />
|
|
12
|
-
<script src="./init.js"></script>
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
16
|
-
<k-main>
|
|
17
|
-
<h1>File System Utilities</h1>
|
|
1
|
+
<page pageName="File System Utilities" title="File System Utilities - Kempo Server">
|
|
2
|
+
<content>
|
|
18
3
|
<p>The file system utilities provide common file and directory operations with Promise-based APIs for Node.js applications.</p>
|
|
19
4
|
|
|
20
5
|
<h2>Installation</h2>
|
|
@@ -113,8 +98,5 @@ async function backupProject() {
|
|
|
113
98
|
<li>Functions handle errors appropriately (e.g., ensureDir ignores EEXIST)</li>
|
|
114
99
|
<li>copyDir preserves directory structure recursively</li>
|
|
115
100
|
</ul>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
119
|
-
</body>
|
|
120
|
-
</html>
|
|
101
|
+
</content>
|
|
102
|
+
</page>
|
|
@@ -1,19 +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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Getting Started</h1>
|
|
1
|
+
<page pageName="Getting Started" title="Getting Started - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Get up and running with Kempo Server in just a few steps.</p>
|
|
18
4
|
|
|
19
5
|
<h2>Installation</h2>
|
|
@@ -73,8 +59,5 @@
|
|
|
73
59
|
<li><a href="middleware.html">Middleware</a> - Add authentication, logging, CORS, and more</li>
|
|
74
60
|
<li><a href="examples.html">Examples & Demos</a> - See real-world examples in action</li>
|
|
75
61
|
</ul>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
79
|
-
</body>
|
|
80
|
-
</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,19 +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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Middleware</h1>
|
|
1
|
+
<page pageName="Middleware" title="Middleware - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Kempo Server includes a powerful middleware system that allows you to add functionality like authentication, logging, CORS, compression, and more.</p>
|
|
18
4
|
|
|
19
5
|
<h2>How Middleware Works</h2>
|
|
@@ -143,8 +129,5 @@
|
|
|
143
129
|
<li>Cache expensive operations when possible</li>
|
|
144
130
|
<li>Consider the performance impact of middleware order</li>
|
|
145
131
|
</ul>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
149
|
-
</body>
|
|
150
|
-
</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,19 +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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Request & Response Objects</h1>
|
|
1
|
+
<page pageName="Request & Response Objects" title="Request & Response Objects - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Learn how to work with HTTP requests and responses in Kempo Server.</p>
|
|
18
4
|
|
|
19
5
|
<h2>Request Object</h2>
|
|
@@ -106,8 +92,5 @@
|
|
|
106
92
|
|
|
107
93
|
<h3>Request Validation</h3>
|
|
108
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>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
112
|
-
</body>
|
|
113
|
-
</html>
|
|
95
|
+
</content>
|
|
96
|
+
</page>
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<meta charset='utf-8'>
|
|
4
|
-
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
|
5
|
-
<title>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="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>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<k-import src="./nav.inc.html"></k-import>
|
|
15
|
-
<k-main>
|
|
16
|
-
<h1>Routing</h1>
|
|
1
|
+
<page pageName="Routing" title="Routing - Kempo Server">
|
|
2
|
+
<content>
|
|
17
3
|
<p>Learn how Kempo Server's file-based routing system works.</p>
|
|
18
4
|
|
|
19
5
|
<h2>How Routes Work</h2>
|
|
@@ -83,8 +69,5 @@
|
|
|
83
69
|
<li><code>index.html</code> / <code>index.htm</code> — served as static</li>
|
|
84
70
|
</ol>
|
|
85
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>
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/kempo-ui@0.0.42/dist/components/Import.js"></script>
|
|
89
|
-
</body>
|
|
90
|
-
</html>
|
|
72
|
+
</content>
|
|
73
|
+
</page>
|