zyket 1.2.13 → 1.2.14
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
|
@@ -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,27 @@ 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
|
|
29
|
-
//
|
|
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
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const previewPort = this.#viteServer.httpServer?.address()?.port ?? this.#port;
|
|
46
|
+
this.#container.get("logger").info(
|
|
47
|
+
`Vite preview server running on http://localhost:${previewPort} (root: ${this.#root})`
|
|
48
|
+
);
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
36
51
|
|