Zestysson commited on
Commit ·
b64dfae
1
Parent(s): ed2272f
Fix: resolve CJS path fileURLToPath runtime error
Browse files
server.ts
CHANGED
|
@@ -7,8 +7,12 @@ import { fileURLToPath } from 'url';
|
|
| 7 |
|
| 8 |
dotenv.config();
|
| 9 |
|
| 10 |
-
const
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
async function startServer() {
|
| 14 |
const app = express();
|
|
@@ -147,9 +151,9 @@ Do not wrap in markdown or any code blocks, return only raw JSON. Ensure it is v
|
|
| 147 |
// Serve static assets or use Vite dev server
|
| 148 |
const isProd = process.env.NODE_ENV === 'production';
|
| 149 |
if (isProd) {
|
| 150 |
-
app.use(express.static(path.join(
|
| 151 |
app.get('*', (req, res) => {
|
| 152 |
-
res.sendFile(path.join(
|
| 153 |
});
|
| 154 |
} else {
|
| 155 |
const vite = await createViteServer({
|
|
|
|
| 7 |
|
| 8 |
dotenv.config();
|
| 9 |
|
| 10 |
+
const resolvedFilename = typeof import.meta !== 'undefined' && import.meta.url
|
| 11 |
+
? fileURLToPath(import.meta.url)
|
| 12 |
+
: __filename;
|
| 13 |
+
const resolvedDirname = typeof import.meta !== 'undefined' && import.meta.url
|
| 14 |
+
? path.dirname(resolvedFilename)
|
| 15 |
+
: __dirname;
|
| 16 |
|
| 17 |
async function startServer() {
|
| 18 |
const app = express();
|
|
|
|
| 151 |
// Serve static assets or use Vite dev server
|
| 152 |
const isProd = process.env.NODE_ENV === 'production';
|
| 153 |
if (isProd) {
|
| 154 |
+
app.use(express.static(path.join(resolvedDirname, 'dist')));
|
| 155 |
app.get('*', (req, res) => {
|
| 156 |
+
res.sendFile(path.join(resolvedDirname, 'dist', 'index.html'));
|
| 157 |
});
|
| 158 |
} else {
|
| 159 |
const vite = await createViteServer({
|