Skip to content

Commit 989d26d

Browse files
authored
Merge pull request #67 from oslabs-beta/user0824/feat/dashboard
feat: updated server file to look for the PORT
2 parents fa31df7 + 29f3760 commit 989d26d

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

server/src/index.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@ import { initializeWebSocket } from './services/websocketService';
1717

1818
const app = express();
1919
const secret = await getSecretKeys(); // Load secrets from Google Secret Manager
20-
const port = secret.PORT;
20+
// Use Cloud Run's PORT env var if available, otherwise fall back to secret or default
21+
const port = process.env.PORT || secret.PORT || 3000;
2122
const server = createServer(app);
2223

2324
// Initialize WebSocket
2425
initializeWebSocket(server);
2526

2627
// ------------------------------------------------------------------------------------------------
27-
// * K8s EVENT WATCHER & PROCESSOR
28+
// * K8s EVENT WATCHER & PROCESSOR (Started after server is running)
2829
// ------------------------------------------------------------------------------------------------
29-
startK8sEventWatcher().catch((err) =>
30-
console.error(chalk.redBright('Failed to start K8s watcher:', err)),
31-
); // Start Kubernetes event watcher
32-
33-
startK8sEventProcessor().catch((err) =>
34-
console.error(chalk.redBright('Failed to start K8s processor:', err)),
35-
); // Start Kubernetes event processor
30+
// Start these services asynchronously after server starts to prevent blocking
31+
setTimeout(() => {
32+
startK8sEventWatcher().catch((err) =>
33+
console.error(chalk.redBright('Failed to start K8s watcher:', err)),
34+
); // Start Kubernetes event watcher
35+
36+
startK8sEventProcessor().catch((err) =>
37+
console.error(chalk.redBright('Failed to start K8s processor:', err)),
38+
); // Start Kubernetes event processor
39+
}, 2000); // Wait 2 seconds after server starts
3640

3741
// ------------------------------------------------------------------------------------------------
3842
// * MIDDLEWARE
@@ -49,6 +53,15 @@ app.get('/status', (req, res) => {
4953
res.status(200).json({ status: 'online', message: 'Server is online!' });
5054
});
5155

56+
// Health check endpoints for Cloud Run
57+
app.get('/health', (req, res) => {
58+
res.status(200).json({ status: 'healthy', timestamp: new Date().toISOString() });
59+
});
60+
61+
app.get('/ready', (req, res) => {
62+
res.status(200).json({ status: 'ready', timestamp: new Date().toISOString() });
63+
});
64+
5265
app.use(express.json()); // EXPRESS
5366
app.use('/api', routes); // ROUTES
5467
app.use('/api/gke', clusterRouter);

server/vite.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export default defineConfig({
3131
'cors',
3232
'dotenv',
3333
'express',
34-
'redis'
34+
'google-auth-library',
35+
'js-yaml',
36+
'redis',
37+
'socket.io'
3538
],
3639
output: {
3740
dir: 'dist',

0 commit comments

Comments
 (0)