@aikotools/repo-maintenance 1.1.2 → 1.2.1
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/dist/server/server/index.js +24 -2
- package/package.json +1 -1
|
@@ -92,9 +92,11 @@ app.all('/trpc/*', async (c) => {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
// Serve static files from dist/client in production
|
|
95
|
+
// serveStatic always prefixes paths with "./" so root must be relative to cwd
|
|
95
96
|
const clientDir = path.join(packageRoot, 'dist/client');
|
|
97
|
+
const clientRoot = path.relative(process.cwd(), clientDir);
|
|
96
98
|
if (existsSync(clientDir)) {
|
|
97
|
-
app.use('/*', serveStatic({ root:
|
|
99
|
+
app.use('/*', serveStatic({ root: clientRoot }));
|
|
98
100
|
// SPA fallback: serve index.html for non-API routes
|
|
99
101
|
app.get('*', async (c) => {
|
|
100
102
|
const indexPath = path.join(clientDir, 'index.html');
|
|
@@ -110,9 +112,29 @@ app.onError((err, c) => {
|
|
|
110
112
|
console.error('[RepoHub] Error:', err.message);
|
|
111
113
|
return c.json({ error: err.message }, 500);
|
|
112
114
|
});
|
|
113
|
-
const
|
|
115
|
+
const preferredPort = Number(process.env.PORT) || 3100;
|
|
116
|
+
async function findAvailablePort(start) {
|
|
117
|
+
const { createServer } = await import('net');
|
|
118
|
+
let port = start;
|
|
119
|
+
while (port < start + 20) {
|
|
120
|
+
const available = await new Promise((resolve) => {
|
|
121
|
+
const server = createServer();
|
|
122
|
+
server.once('error', () => resolve(false));
|
|
123
|
+
server.once('listening', () => server.close(() => resolve(true)));
|
|
124
|
+
server.listen(port);
|
|
125
|
+
});
|
|
126
|
+
if (available)
|
|
127
|
+
return port;
|
|
128
|
+
port++;
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`No available port found between ${start} and ${port}`);
|
|
131
|
+
}
|
|
132
|
+
const port = await findAvailablePort(preferredPort);
|
|
114
133
|
serve({
|
|
115
134
|
fetch: app.fetch,
|
|
116
135
|
port,
|
|
117
136
|
});
|
|
137
|
+
if (port !== preferredPort) {
|
|
138
|
+
console.log(`[RepoHub] Port ${preferredPort} in use, using ${port} instead`);
|
|
139
|
+
}
|
|
118
140
|
console.log(`[RepoHub] Server running on http://localhost:${port}`);
|