Fix Vercel deploy: build dist and run Express as serverless.

This commit is contained in:
b1rdmania
2025-12-18 19:16:47 +00:00
parent 1b10f006f9
commit 96477e9c4a
3 changed files with 30 additions and 8 deletions
+9 -3
View File
@@ -83,6 +83,12 @@ app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
app.listen(port, () => {
console.log(`🎵 Motif backend running on port ${port}`);
});
// Vercel serverless runtime expects an exported handler (Express apps are handlers).
// Locally, we still want to run a dev server with `app.listen`.
export default app;
if (!process.env.VERCEL) {
app.listen(port, () => {
console.log(`🎵 Motif backend running on port ${port}`);
});
}
+14 -2
View File
@@ -35,8 +35,20 @@ export class MIDIService {
private baseUrl: string;
constructor(baseUrl?: string) {
// Use environment variable or fallback to localhost for development
this.baseUrl = baseUrl || import.meta.env.VITE_API_URL || 'http://localhost:3001';
// Production (Vercel): prefer same-origin API (no env var needed)
// Dev: default to local backend on :3001
const envUrl = (import.meta as any).env?.VITE_API_URL as string | undefined;
const isDev = Boolean((import.meta as any).env?.DEV);
if (baseUrl) {
this.baseUrl = baseUrl;
} else if (envUrl) {
this.baseUrl = envUrl;
} else if (isDev) {
this.baseUrl = 'http://localhost:3001';
} else {
this.baseUrl = '';
}
}
async search(query: string): Promise<MIDISearchResult[]> {
+7 -3
View File
@@ -2,8 +2,11 @@
"version": 2,
"builds": [
{
"src": "dist/index.html",
"use": "@vercel/static"
"src": "package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "dist"
}
},
{
"src": "server/src/server.ts",
@@ -19,9 +22,10 @@
"src": "/health",
"dest": "server/src/server.ts"
},
{ "handle": "filesystem" },
{
"src": "/(.*)",
"dest": "/dist/$1"
"dest": "/index.html"
}
]
}