Sasha commited on
Commit
083990e
·
1 Parent(s): 687f807

chore: handle missing client dist path gracefully in server

Browse files
Files changed (1) hide show
  1. server/server.js +19 -5
server/server.js CHANGED
@@ -4,6 +4,7 @@ import cookieSession from 'cookie-session';
4
  import dotenv from 'dotenv';
5
  import axios from 'axios';
6
  import path from 'path';
 
7
  import {
8
  logChatMessage,
9
  logVoiceWords,
@@ -912,11 +913,24 @@ async function pollTwitchStreamStatus() {
912
  // Serve static frontend files in production
913
  if (process.env.NODE_ENV === 'production') {
914
  const __dirname = new URL('.', import.meta.url).pathname;
915
- // Express static client serve
916
- app.use(express.static('../client/dist'));
917
- app.get('*', (req, res) => {
918
- res.sendFile(path.resolve(__dirname, '../client/dist', 'index.html'));
919
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
920
  }
921
 
922
  // Start Server
 
4
  import dotenv from 'dotenv';
5
  import axios from 'axios';
6
  import path from 'path';
7
+ import fs from 'fs';
8
  import {
9
  logChatMessage,
10
  logVoiceWords,
 
913
  // Serve static frontend files in production
914
  if (process.env.NODE_ENV === 'production') {
915
  const __dirname = new URL('.', import.meta.url).pathname;
916
+ const clientDistPath = path.resolve(__dirname, '../client/dist');
917
+
918
+ if (fs.existsSync(clientDistPath)) {
919
+ // Express static client serve
920
+ app.use(express.static(clientDistPath));
921
+ app.get('*', (req, res) => {
922
+ res.sendFile(path.resolve(clientDistPath, 'index.html'));
923
+ });
924
+ } else {
925
+ // In decoupled mode (Hugging Face API-only), serve a simple JSON status page on root
926
+ app.get('/', (req, res) => {
927
+ res.json({
928
+ status: 'online',
929
+ message: 'winx_prinx API Server is running',
930
+ environment: 'production'
931
+ });
932
+ });
933
+ }
934
  }
935
 
936
  // Start Server