agent-window 1.0.2 → 1.0.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/package.json +1 -1
- package/src/api/server.js +22 -13
package/package.json
CHANGED
package/src/api/server.js
CHANGED
|
@@ -75,23 +75,32 @@ export function createServer(options = {}) {
|
|
|
75
75
|
registerWebSocket(fastify);
|
|
76
76
|
|
|
77
77
|
// Serve static files (frontend build)
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
// __dirname is src/api/, so we go up two levels to package root, then into web/dist
|
|
79
|
+
const distPath = join(__dirname, '..', '..', 'web', 'dist');
|
|
80
|
+
const hasDist = existsSync(distPath);
|
|
81
|
+
|
|
82
|
+
if (hasDist) {
|
|
80
83
|
fastify.register(fastifyStatic, {
|
|
81
84
|
root: distPath,
|
|
82
|
-
prefix: '/'
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// SPA fallback - serve index.html for non-API routes
|
|
86
|
-
fastify.setNotFoundHandler(async (request, reply) => {
|
|
87
|
-
if (request.url.startsWith('/api/') || request.url.startsWith('/ws/')) {
|
|
88
|
-
reply.code(404).send({ error: 'Not found' });
|
|
89
|
-
} else {
|
|
90
|
-
reply.sendFile('index.html');
|
|
91
|
-
}
|
|
85
|
+
prefix: '/',
|
|
86
|
+
decorateReply: false
|
|
92
87
|
});
|
|
93
88
|
}
|
|
94
89
|
|
|
90
|
+
// SPA fallback - serve index.html for non-API routes (if dist exists)
|
|
91
|
+
fastify.setNotFoundHandler(async (request, reply) => {
|
|
92
|
+
if (request.url.startsWith('/api/') || request.url.startsWith('/ws/')) {
|
|
93
|
+
reply.code(404).send({ error: 'Not found' });
|
|
94
|
+
} else if (hasDist) {
|
|
95
|
+
reply.sendFile('index.html');
|
|
96
|
+
} else {
|
|
97
|
+
reply.code(500).send({
|
|
98
|
+
error: 'Frontend not built',
|
|
99
|
+
message: 'The web UI assets are not available. Please report this issue.'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
95
104
|
// Graceful shutdown
|
|
96
105
|
const gracefulShutdown = async (signal) => {
|
|
97
106
|
fastify.log.info(`Received ${signal}, shutting down gracefully...`);
|
|
@@ -110,7 +119,7 @@ export function createServer(options = {}) {
|
|
|
110
119
|
*/
|
|
111
120
|
export function getPackageVersion() {
|
|
112
121
|
try {
|
|
113
|
-
const pkgPath = join(
|
|
122
|
+
const pkgPath = join(__dirname, '..', '..', 'package.json');
|
|
114
123
|
const pkg = require(pkgPath);
|
|
115
124
|
return pkg.version || 'unknown';
|
|
116
125
|
} catch {
|