statikapi 0.3.0 → 0.4.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/README.md
CHANGED
|
@@ -23,10 +23,8 @@ pnpm add -D statikapi
|
|
|
23
23
|
statikapi <command> [options]
|
|
24
24
|
|
|
25
25
|
Commands:
|
|
26
|
-
init Scaffold a new StatikAPI project
|
|
27
26
|
build Build static JSON endpoints
|
|
28
27
|
dev Watch & rebuild on changes
|
|
29
|
-
preview Serve the built JSON files + UI
|
|
30
28
|
|
|
31
29
|
Global:
|
|
32
30
|
-h, --help Show help
|
package/package.json
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "statikapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/zonayedpca/statikapi",
|
|
7
7
|
"directory": "packages/cli"
|
|
8
8
|
},
|
|
9
|
-
"bugs": {
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/zonayedpca/statikapi/issues"
|
|
11
|
+
},
|
|
10
12
|
"homepage": "https://github.com/zonayedpca/statikapi#readme",
|
|
11
13
|
"type": "module",
|
|
12
|
-
"bin": {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
14
|
+
"bin": {
|
|
15
|
+
"statikapi": "bin/statikapi.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"dist",
|
|
20
|
+
"ui",
|
|
21
|
+
"src",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./src/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
16
33
|
"license": "MIT",
|
|
17
|
-
"keywords": [
|
|
18
|
-
|
|
34
|
+
"keywords": [
|
|
35
|
+
"static",
|
|
36
|
+
"json",
|
|
37
|
+
"api",
|
|
38
|
+
"cli",
|
|
39
|
+
"ssg"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
},
|
|
19
45
|
"dependencies": {
|
|
20
46
|
"chokidar": "^3.6.0",
|
|
21
47
|
"sirv": "^2.0.4",
|
package/src/commands/dev.js
CHANGED
|
@@ -367,6 +367,39 @@ export default async function devCmd(argv) {
|
|
|
367
367
|
return;
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
// 6) Serve built JSON directly from api-out
|
|
371
|
+
{
|
|
372
|
+
const outRoot = config.paths.outAbs;
|
|
373
|
+
// strip leading slash and normalize
|
|
374
|
+
const rel = pathname.replace(/^\/+/, '');
|
|
375
|
+
const candidates = [];
|
|
376
|
+
|
|
377
|
+
// If the request ends with .json, try that file directly
|
|
378
|
+
if (rel.endsWith('.json')) {
|
|
379
|
+
candidates.push(path.join(outRoot, rel));
|
|
380
|
+
} else {
|
|
381
|
+
// Otherwise, try a folder with index.json (e.g. "/" or "/users/1/")
|
|
382
|
+
candidates.push(path.join(outRoot, rel, 'index.json'));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
for (const cand of candidates) {
|
|
386
|
+
const file = path.resolve(cand);
|
|
387
|
+
// prevent path traversal
|
|
388
|
+
if (!file.startsWith(path.resolve(outRoot))) continue;
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
const st = await fs.stat(file);
|
|
392
|
+
if (st.isFile()) {
|
|
393
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
394
|
+
fss.createReadStream(file).pipe(res);
|
|
395
|
+
return; // served
|
|
396
|
+
}
|
|
397
|
+
} catch {
|
|
398
|
+
// try next candidate
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
370
403
|
// Otherwise: 404
|
|
371
404
|
res.statusCode = 404;
|
|
372
405
|
res.end('Not Found');
|
package/src/help.js
CHANGED
|
@@ -3,11 +3,9 @@ export const HELP = `statikapi — Static API generator
|
|
|
3
3
|
Usage:
|
|
4
4
|
statikapi <command> [options]
|
|
5
5
|
|
|
6
|
-
Commands:
|
|
7
|
-
init Scaffold a new StatikAPI project
|
|
6
|
+
Commands:Scaffold a new StatikAPI project
|
|
8
7
|
build Build static JSON endpoints
|
|
9
8
|
dev Start dev mode (watch & rebuild)
|
|
10
|
-
preview Serve the built JSON files
|
|
11
9
|
|
|
12
10
|
Global options:
|
|
13
11
|
-h, --help Show help
|