@axiom-lattice/web 0.1.1 → 0.1.3
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 +1 -20
- package/dist/{server.js → server.cjs} +15 -18
- package/dist/server.cjs.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ pnpm build
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
This will:
|
|
33
|
+
|
|
33
34
|
1. Build the React application with Vite
|
|
34
35
|
2. Build the server script for CLI usage
|
|
35
36
|
|
|
@@ -39,12 +40,6 @@ This will:
|
|
|
39
40
|
pnpm start
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
Or use the CLI directly:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
lattice-web
|
|
46
|
-
```
|
|
47
|
-
|
|
48
43
|
### Using npx (after publishing)
|
|
49
44
|
|
|
50
45
|
```bash
|
|
@@ -59,20 +54,6 @@ npx @axiom-lattice/web -p 8080
|
|
|
59
54
|
PORT=8080 npx @axiom-lattice/web
|
|
60
55
|
```
|
|
61
56
|
|
|
62
|
-
### CLI Options
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
# Start on default port 4000
|
|
66
|
-
lattice-web
|
|
67
|
-
|
|
68
|
-
# Start on a custom port
|
|
69
|
-
lattice-web --port 8080
|
|
70
|
-
lattice-web -p 8080
|
|
71
|
-
|
|
72
|
-
# Use environment variable
|
|
73
|
-
PORT=8080 lattice-web
|
|
74
|
-
```
|
|
75
|
-
|
|
76
57
|
## Learn More
|
|
77
58
|
|
|
78
59
|
To learn more about **Refine**, please check out the [Documentation](https://refine.dev/docs)
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
"use strict";
|
|
3
3
|
|
|
4
4
|
// src/server.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
9
|
-
import { dirname } from "path";
|
|
10
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
var __dirname = dirname(__filename);
|
|
5
|
+
var import_http = require("http");
|
|
6
|
+
var import_fs = require("fs");
|
|
7
|
+
var import_path = require("path");
|
|
12
8
|
var MIME_TYPES = {
|
|
13
9
|
".html": "text/html",
|
|
14
10
|
".js": "application/javascript",
|
|
@@ -51,35 +47,35 @@ function getPort() {
|
|
|
51
47
|
}
|
|
52
48
|
function startServer() {
|
|
53
49
|
const port = getPort();
|
|
54
|
-
const distPath = join(__dirname, "..", "dist");
|
|
55
|
-
const indexPath = join(distPath, "index.html");
|
|
56
|
-
if (!existsSync(distPath)) {
|
|
50
|
+
const distPath = (0, import_path.join)(__dirname, "..", "dist");
|
|
51
|
+
const indexPath = (0, import_path.join)(distPath, "index.html");
|
|
52
|
+
if (!(0, import_fs.existsSync)(distPath)) {
|
|
57
53
|
console.error(`Error: dist folder not found at ${distPath}`);
|
|
58
54
|
console.error(
|
|
59
55
|
"Please run 'pnpm build' first to build the web application."
|
|
60
56
|
);
|
|
61
57
|
process.exit(1);
|
|
62
58
|
}
|
|
63
|
-
if (!existsSync(indexPath)) {
|
|
59
|
+
if (!(0, import_fs.existsSync)(indexPath)) {
|
|
64
60
|
console.error(`Error: index.html not found at ${indexPath}`);
|
|
65
61
|
console.error(
|
|
66
62
|
"Please run 'pnpm build' first to build the web application."
|
|
67
63
|
);
|
|
68
64
|
process.exit(1);
|
|
69
65
|
}
|
|
70
|
-
const server = createServer((req, res) => {
|
|
66
|
+
const server = (0, import_http.createServer)((req, res) => {
|
|
71
67
|
const url = req.url || "/";
|
|
72
|
-
let filePath = join(distPath, url === "/" ? "index.html" : url);
|
|
68
|
+
let filePath = (0, import_path.join)(distPath, url === "/" ? "index.html" : url);
|
|
73
69
|
if (!filePath.startsWith(distPath)) {
|
|
74
70
|
res.writeHead(403);
|
|
75
71
|
res.end("Forbidden");
|
|
76
72
|
return;
|
|
77
73
|
}
|
|
78
|
-
if (existsSync(filePath) && statSync(filePath).isFile()) {
|
|
79
|
-
const ext = extname(filePath);
|
|
74
|
+
if ((0, import_fs.existsSync)(filePath) && (0, import_fs.statSync)(filePath).isFile()) {
|
|
75
|
+
const ext = (0, import_path.extname)(filePath);
|
|
80
76
|
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
81
77
|
try {
|
|
82
|
-
const content = readFileSync(filePath);
|
|
78
|
+
const content = (0, import_fs.readFileSync)(filePath);
|
|
83
79
|
res.writeHead(200, { "Content-Type": contentType });
|
|
84
80
|
res.end(content);
|
|
85
81
|
} catch (err) {
|
|
@@ -88,7 +84,7 @@ function startServer() {
|
|
|
88
84
|
}
|
|
89
85
|
} else {
|
|
90
86
|
try {
|
|
91
|
-
const content = readFileSync(indexPath);
|
|
87
|
+
const content = (0, import_fs.readFileSync)(indexPath);
|
|
92
88
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
93
89
|
res.end(content);
|
|
94
90
|
} catch (err) {
|
|
@@ -121,3 +117,4 @@ function startServer() {
|
|
|
121
117
|
});
|
|
122
118
|
}
|
|
123
119
|
startServer();
|
|
120
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { createServer } from \"http\";\nimport { readFileSync, existsSync, statSync } from \"fs\";\nimport { join, extname } from \"path\";\n\n// MIME types for common file extensions\nconst MIME_TYPES: Record<string, string> = {\n \".html\": \"text/html\",\n \".js\": \"application/javascript\",\n \".mjs\": \"application/javascript\",\n \".css\": \"text/css\",\n \".json\": \"application/json\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".svg\": \"image/svg+xml\",\n \".ico\": \"image/x-icon\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n};\n\n/**\n * Get port from command line arguments or environment variable\n */\nfunction getPort(): number {\n const args = process.argv.slice(2);\n\n // Check for --port or -p flag\n const portIndex = args.findIndex((arg) => arg === \"--port\" || arg === \"-p\");\n if (portIndex !== -1 && args[portIndex + 1]) {\n const port = parseInt(args[portIndex + 1], 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid port value: ${args[portIndex + 1]}, using default port 4000`\n );\n }\n\n // Check for PORT environment variable\n if (process.env.PORT) {\n const port = parseInt(process.env.PORT, 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid PORT environment variable: ${process.env.PORT}, using default port 4000`\n );\n }\n\n return 4000;\n}\n\n/**\n * Start the static file server\n */\nfunction startServer(): void {\n const port = getPort();\n\n // Determine the dist directory path\n // When running from dist/server.js, the dist folder is in the parent directory\n const distPath = join(__dirname, \"..\", \"dist\");\n const indexPath = join(distPath, \"index.html\");\n\n // Check if dist folder exists\n if (!existsSync(distPath)) {\n console.error(`Error: dist folder not found at ${distPath}`);\n console.error(\n \"Please run 'pnpm build' first to build the web application.\"\n );\n process.exit(1);\n }\n\n // Check if index.html exists\n if (!existsSync(indexPath)) {\n console.error(`Error: index.html not found at ${indexPath}`);\n console.error(\n \"Please run 'pnpm build' first to build the web application.\"\n );\n process.exit(1);\n }\n\n const server = createServer((req, res) => {\n const url = req.url || \"/\";\n let filePath = join(distPath, url === \"/\" ? \"index.html\" : url);\n\n // Security: prevent path traversal\n if (!filePath.startsWith(distPath)) {\n res.writeHead(403);\n res.end(\"Forbidden\");\n return;\n }\n\n // Check if file exists\n if (existsSync(filePath) && statSync(filePath).isFile()) {\n const ext = extname(filePath);\n const contentType = MIME_TYPES[ext] || \"application/octet-stream\";\n\n try {\n const content = readFileSync(filePath);\n res.writeHead(200, { \"Content-Type\": contentType });\n res.end(content);\n } catch (err) {\n res.writeHead(500);\n res.end(\"Internal Server Error\");\n }\n } else {\n // SPA fallback: serve index.html for all non-file routes\n try {\n const content = readFileSync(indexPath);\n res.writeHead(200, { \"Content-Type\": \"text/html\" });\n res.end(content);\n } catch (err) {\n res.writeHead(500);\n res.end(\"Internal Server Error\");\n }\n }\n });\n\n server.listen(port, () => {\n console.log(\n `\\n🚀 Axiom Lattice Web is running at http://localhost:${port}`\n );\n console.log(` Gateway connection: http://localhost:4001`);\n console.log(`\\n Press Ctrl+C to stop the server.\\n`);\n });\n\n // Graceful shutdown\n process.on(\"SIGINT\", () => {\n console.log(\"\\n👋 Shutting down server...\");\n server.close(() => {\n console.log(\"Server closed.\");\n process.exit(0);\n });\n });\n\n process.on(\"SIGTERM\", () => {\n server.close(() => {\n process.exit(0);\n });\n });\n}\n\n// Start the server\nstartServer();\n"],"mappings":";;;;AAAA,kBAA6B;AAC7B,gBAAmD;AACnD,kBAA8B;AAG9B,IAAM,aAAqC;AAAA,EACzC,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AACV;AAKA,SAAS,UAAkB;AACzB,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAGjC,QAAM,YAAY,KAAK,UAAU,CAAC,QAAQ,QAAQ,YAAY,QAAQ,IAAI;AAC1E,MAAI,cAAc,MAAM,KAAK,YAAY,CAAC,GAAG;AAC3C,UAAM,OAAO,SAAS,KAAK,YAAY,CAAC,GAAG,EAAE;AAC7C,QAAI,CAAC,MAAM,IAAI,KAAK,OAAO,KAAK,OAAO,OAAO;AAC5C,aAAO;AAAA,IACT;AACA,YAAQ;AAAA,MACN,uBAAuB,KAAK,YAAY,CAAC,CAAC;AAAA,IAC5C;AAAA,EACF;AAGA,MAAI,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,IAAI,uBAAuB;AAAA,MACjC;AAAA,IACF,OAAO;AAEL,UAAI;AACF,cAAM,cAAU,wBAAa,SAAS;AACtC,YAAI,UAAU,KAAK,EAAE,gBAAgB,YAAY,CAAC;AAClD,YAAI,IAAI,OAAO;AAAA,MACjB,SAAS,KAAK;AACZ,YAAI,UAAU,GAAG;AACjB,YAAI,IAAI,uBAAuB;AAAA,MACjC;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,OAAO,MAAM,MAAM;AACxB,YAAQ;AAAA,MACN;AAAA,6DAAyD,IAAI;AAAA,IAC/D;AACA,YAAQ,IAAI,8CAA8C;AAC1D,YAAQ,IAAI;AAAA;AAAA,CAAyC;AAAA,EACvD,CAAC;AAGD,UAAQ,GAAG,UAAU,MAAM;AACzB,YAAQ,IAAI,qCAA8B;AAC1C,WAAO,MAAM,MAAM;AACjB,cAAQ,IAAI,gBAAgB;AAC5B,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AAED,UAAQ,GAAG,WAAW,MAAM;AAC1B,WAAO,MAAM,MAAM;AACjB,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AACH;AAGA,YAAY;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiom-lattice/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"lattice-web": "./dist/server.
|
|
6
|
+
"lattice-web": "./dist/server.cjs"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"dev": "refine dev",
|
|
67
67
|
"build": "tsc && refine build && tsup",
|
|
68
68
|
"build:server": "tsup",
|
|
69
|
-
"start": "node dist/server.
|
|
70
|
-
"serve": "node dist/server.
|
|
69
|
+
"start": "node dist/server.cjs",
|
|
70
|
+
"serve": "node dist/server.cjs",
|
|
71
71
|
"refine": "refine",
|
|
72
72
|
"up_lattice": "pnpm up @axiom-lattice/react-sdk@latest"
|
|
73
73
|
}
|