Skip to content

Commit c18294c

Browse files
authored
Merge pull request #14 from techstartucalgary/reconstruct-backend-pipeline
update serverless index for deployment
2 parents 7afcb92 + 09fa55d commit c18294c

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

.github/workflows/backend.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

shatter-backend/api/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'dotenv/config';
2+
import mongoose from 'mongoose';
3+
import app from '../src/app';
4+
5+
const MONGODB_URI = process.env.MONGO_URI;
6+
7+
let cachedConnection: typeof mongoose | null = null;
8+
9+
async function connectDB() {
10+
if (cachedConnection) {
11+
return cachedConnection;
12+
}
13+
14+
if (!MONGODB_URI) {
15+
throw new Error('MONGO_URI is not set in environment variables');
16+
}
17+
18+
const conn = await mongoose.connect(MONGODB_URI, {
19+
bufferCommands: false,
20+
});
21+
22+
cachedConnection = conn;
23+
return conn;
24+
}
25+
26+
connectDB().catch((err) => {
27+
console.error('Failed to connect to MongoDB:', err);
28+
});
29+
30+
export default app;

shatter-backend/tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"esModuleInterop": true,
77
"strict": true,
88
"sourceMap": true,
9-
"outDir": "dist",
10-
"lib": ["ES2021"],
11-
"noEmit": false
9+
"outDir": "./dist",
10+
"rootDir": "./",
11+
"lib": ["ES2021"]
1212
},
13-
"include": ["src/**/*"]
14-
}
13+
"include": ["src/**/*", "api/**/*"],
14+
"exclude": ["node_modules", "dist"]
15+
}

shatter-backend/vercel.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"version": 2,
33
"builds": [
4-
{ "src": "dist/server.js", "use": "@vercel/node" }
4+
{
5+
"src": "dist/api/index.js",
6+
"use": "@vercel/node"
7+
}
58
],
69
"routes": [
7-
{ "src": "/(.*)", "dest": "dist/server.js" }
10+
{
11+
"src": "/(.*)",
12+
"dest": "dist/api/index.js"
13+
}
814
]
915
}

0 commit comments

Comments
 (0)