|
@@ -1,5 +1,5 @@
|
|
|
import express from 'express';
|
|
import express from 'express';
|
|
|
-import { readFileSync } from 'fs';
|
|
|
|
|
|
|
+import { readFileSync, existsSync } from 'fs';
|
|
|
import { resolve, dirname } from 'path';
|
|
import { resolve, dirname } from 'path';
|
|
|
import { fileURLToPath } from 'url';
|
|
import { fileURLToPath } from 'url';
|
|
|
import type { WordBank } from '@wordle/shared';
|
|
import type { WordBank } from '@wordle/shared';
|
|
@@ -34,9 +34,11 @@ for (const [path, router] of [...mountApi('/api', enBank), ...mountApi('/ru/api'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Serve SPA
|
|
// Serve SPA
|
|
|
-const clientDist = process.env.STATIC_DIR
|
|
|
|
|
- ? resolve(process.env.STATIC_DIR)
|
|
|
|
|
- : resolve(__dirname, '../../client/dist');
|
|
|
|
|
|
|
+const clientDist = (() => {
|
|
|
|
|
+ if (process.env.STATIC_DIR) return resolve(process.env.STATIC_DIR);
|
|
|
|
|
+ const devPath = resolve(__dirname, '../../client/dist');
|
|
|
|
|
+ return existsSync(devPath) ? devPath : resolve(__dirname, '../../client');
|
|
|
|
|
+})();
|
|
|
app.use(express.static(clientDist));
|
|
app.use(express.static(clientDist));
|
|
|
app.get('/{*path}', (_req, res) => {
|
|
app.get('/{*path}', (_req, res) => {
|
|
|
res.sendFile(resolve(clientDist, 'index.html'));
|
|
res.sendFile(resolve(clientDist, 'index.html'));
|