@kirkelliott/zap 0.1.15 → 0.1.16

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/demo/index.zap ADDED
@@ -0,0 +1,39 @@
1
+ export default async (req) => {
2
+ const base = `${req.headers['x-forwarded-proto'] ?? 'https'}://${req.headers['host']}`
3
+ const demos = [
4
+ ['hello', 'hello world'],
5
+ ['counter', 'persistent counter'],
6
+ ['visitors', 'visitor count'],
7
+ ['echo', 'echo request details'],
8
+ ['kv', 'key/value store'],
9
+ ['proxy', 'cors proxy — add ?url='],
10
+ ]
11
+ return {
12
+ headers: { 'content-type': 'text/html' },
13
+ body: `<!doctype html>
14
+ <html>
15
+ <head><meta charset="utf-8"><title>zap</title>
16
+ <style>
17
+ * { box-sizing: border-box; }
18
+ body { font-family: -apple-system, sans-serif; max-width: 520px; margin: 5rem auto; padding: 0 2rem; color: #111; }
19
+ h1 { font-size: 1.25rem; font-weight: 700; margin: 0 0 0.25rem; }
20
+ .sub { color: #666; font-size: 0.875rem; margin: 0 0 2.5rem; }
21
+ .sub a { color: #666; }
22
+ ul { list-style: none; padding: 0; margin: 0; }
23
+ li { display: flex; align-items: baseline; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid #f0f0f0; }
24
+ li:last-child { border-bottom: none; }
25
+ a.route { font-family: monospace; font-size: 0.9rem; color: #111; text-decoration: none; }
26
+ a.route:hover { text-decoration: underline; }
27
+ span { color: #999; font-size: 0.8rem; }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <h1>zap demos</h1>
32
+ <p class="sub">Drop a .zap file in S3. It becomes an endpoint. &mdash; <a href="https://github.com/dmvjs/s3node">github</a></p>
33
+ <ul>
34
+ ${demos.map(([slug, desc]) => `<li><a class="route" href="${base}/demo/${slug}">/demo/${slug}</a><span>${desc}</span></li>`).join('\n ')}
35
+ </ul>
36
+ </body>
37
+ </html>`,
38
+ }
39
+ }
package/dist/cli.js CHANGED
@@ -152,7 +152,10 @@ program
152
152
  const { url } = readConfig();
153
153
  const demoDir = (0, node_path_1.resolve)(__dirname, '..', 'demo');
154
154
  const files = await walkZap(demoDir, 'demo');
155
- await Promise.all(files.map(({ filePath, key }) => deployFile(b, filePath, key, url)));
155
+ const remapped = files.map(f => f.key === 'demo/index.zap' ? { ...f, key: 'index.zap' } : f);
156
+ await Promise.all(remapped.map(({ filePath, key }) => deployFile(b, filePath, key, url)));
157
+ if (url)
158
+ console.log(`\n → ${url.trim()}`);
156
159
  });
157
160
  program
158
161
  .command('debug')
package/dist/handler.js CHANGED
@@ -33,7 +33,8 @@ const handler = async (event) => {
33
33
  body: e.body ?? null,
34
34
  };
35
35
  try {
36
- const source = await loader(req.path.replace(/^\//, ''));
36
+ const key = req.path === '/' ? 'index' : req.path.replace(/^\//, '');
37
+ const source = await loader(key);
37
38
  const res = await (0, eval_1.run)(source, req, loader);
38
39
  return { statusCode: res.status ?? 200, headers: res.headers, body: (0, types_1.serialize)(res.body) };
39
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkelliott/zap",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Drop a .zap file in S3. It becomes an API endpoint.",
5
5
  "main": "dist/handler.js",
6
6
  "bin": {