Fix Vercel deploy: build dist and run Express as serverless.
This commit is contained in:
@@ -83,6 +83,12 @@ app.get('/health', (req, res) => {
|
|||||||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
// Vercel serverless runtime expects an exported handler (Express apps are handlers).
|
||||||
console.log(`🎵 Motif backend running on port ${port}`);
|
// 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}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -35,8 +35,20 @@ export class MIDIService {
|
|||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
|
|
||||||
constructor(baseUrl?: string) {
|
constructor(baseUrl?: string) {
|
||||||
// Use environment variable or fallback to localhost for development
|
// Production (Vercel): prefer same-origin API (no env var needed)
|
||||||
this.baseUrl = baseUrl || import.meta.env.VITE_API_URL || 'http://localhost:3001';
|
// 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[]> {
|
async search(query: string): Promise<MIDISearchResult[]> {
|
||||||
|
|||||||
+7
-3
@@ -2,8 +2,11 @@
|
|||||||
"version": 2,
|
"version": 2,
|
||||||
"builds": [
|
"builds": [
|
||||||
{
|
{
|
||||||
"src": "dist/index.html",
|
"src": "package.json",
|
||||||
"use": "@vercel/static"
|
"use": "@vercel/static-build",
|
||||||
|
"config": {
|
||||||
|
"distDir": "dist"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "server/src/server.ts",
|
"src": "server/src/server.ts",
|
||||||
@@ -19,9 +22,10 @@
|
|||||||
"src": "/health",
|
"src": "/health",
|
||||||
"dest": "server/src/server.ts"
|
"dest": "server/src/server.ts"
|
||||||
},
|
},
|
||||||
|
{ "handle": "filesystem" },
|
||||||
{
|
{
|
||||||
"src": "/(.*)",
|
"src": "/(.*)",
|
||||||
"dest": "/dist/$1"
|
"dest": "/index.html"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user