zyket 1.2.13 → 1.2.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.2.13",
3
+ "version": "1.2.15",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -94,10 +94,6 @@ module.exports = class Express extends Service {
94
94
  }
95
95
  });
96
96
 
97
- // In production, serve the built Vite frontend (static assets + SPA fallback).
98
- // Registered after API routes so the API keeps precedence.
99
- this.#serveFrontend();
100
-
101
97
  // Attach Express to HTTP server - this allows dynamic route registration
102
98
  this.#httpServer.removeAllListeners("request");
103
99
  this.#httpServer.on("request", this.#app);
@@ -105,34 +101,6 @@ module.exports = class Express extends Service {
105
101
  this.#container.get('logger').info(`Express is running on http://localhost:${httpServer.address().port}`);
106
102
  }
107
103
 
108
- #serveFrontend() {
109
- const viteEnabled = process.env.VITE_ROOT && process.env.DISABLE_VITE !== 'true';
110
- if (process.env.NODE_ENV !== 'production' || !viteEnabled) return;
111
-
112
- const vite = this.#container.has('vite') ? this.#container.get('vite') : null;
113
- const distPath = vite?.outDir?.()
114
- || path.resolve(process.cwd(), process.env.VITE_ROOT || 'frontend', 'dist');
115
- const indexHtml = path.join(distPath, 'index.html');
116
-
117
- if (!fs.existsSync(indexHtml)) {
118
- this.#container.get('logger').warn(`Frontend build not found at ${distPath}. Skipping static serving.`);
119
- return;
120
- }
121
-
122
- this.#app.use(express.static(distPath));
123
-
124
- // SPA fallback: serve index.html for any GET not handled by API routes,
125
- // except the Swagger docs path. Uses middleware (Express 5 dropped bare '*').
126
- const docsPath = process.env.SWAGGER_PATH || '/docs';
127
- this.#app.use((req, res, next) => {
128
- if (req.method !== 'GET') return next();
129
- if (req.path.startsWith(docsPath)) return next();
130
- res.sendFile(indexHtml);
131
- });
132
-
133
- this.#container.get('logger').info(`Serving frontend from ${distPath}`);
134
- }
135
-
136
104
  async registerRoutes(routes) {
137
105
  const methods = ['post', 'get', 'put', 'delete']
138
106
  for (const route of routes) {
@@ -25,12 +25,31 @@ module.exports = class Vite extends Service {
25
25
 
26
26
  const configFile = this.#resolveConfigFile();
27
27
 
28
- // In production we build the frontend once and let Express serve the
29
- // generated static files. No dev server is started.
28
+ // In production we build the frontend once and serve it with Vite's own
29
+ // preview server on its own port (no dev server, no conflict with Express).
30
30
  if (this.#isProduction) {
31
31
  this.#container.get("logger").info("Building Vite frontend for production...");
32
32
  this.#outDir = await buildViteApp({ root: this.#root, configFile });
33
33
  this.#container.get("logger").info(`Vite build complete (output: ${this.#outDir})`);
34
+
35
+ const { preview } = await import("vite");
36
+ this.#viteServer = await preview({
37
+ root: this.#root,
38
+ configFile,
39
+ preview: {
40
+ port: this.#port,
41
+ strictPort: false,
42
+ // Listen on 0.0.0.0 so a reverse proxy can reach it, and accept
43
+ // requests for any Host (the proxy forwards the public domain).
44
+ host: true,
45
+ allowedHosts: true,
46
+ },
47
+ });
48
+
49
+ const previewPort = this.#viteServer.httpServer?.address()?.port ?? this.#port;
50
+ this.#container.get("logger").info(
51
+ `Vite preview server running on http://localhost:${previewPort} (root: ${this.#root})`
52
+ );
34
53
  return;
35
54
  }
36
55
 
@@ -42,6 +61,8 @@ module.exports = class Vite extends Service {
42
61
  server: {
43
62
  port: this.#port,
44
63
  strictPort: false,
64
+ host: true,
65
+ allowedHosts: true,
45
66
  },
46
67
  });
47
68