Corrigindo crash da API serverless: Removendo dependência do MongoDB e conectando ao Supabase
This commit is contained in:
15
api/index.ts
15
api/index.ts
@@ -1,19 +1,15 @@
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
import app from './app.js';
|
||||
import mongoose from 'mongoose';
|
||||
import { connectDB } from '../src/server/config/database.js';
|
||||
|
||||
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
try {
|
||||
console.log('--- API CALL:', req.url);
|
||||
|
||||
// Inline connection to avoid external file dependency issues during boot
|
||||
if (mongoose.connection.readyState !== 1) {
|
||||
const uri = process.env.MONGODB_URI;
|
||||
if (!uri) throw new Error('MONGODB_URI environment variable is missing');
|
||||
await mongoose.connect(uri);
|
||||
}
|
||||
// Conecta ao Banco de Dados (Supabase/Postgres)
|
||||
await connectDB();
|
||||
|
||||
// Use the localized app.js
|
||||
// Passa o controle para o Express
|
||||
return app(req, res);
|
||||
} catch (error: unknown) {
|
||||
console.error('SERVERLESS BOOT ERROR:', error);
|
||||
@@ -21,8 +17,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
return res.status(500).json({
|
||||
error: 'Serverless Boot Error',
|
||||
message: message,
|
||||
path: req.url,
|
||||
suggestion: 'Check Vercel Logs for module resolution errors'
|
||||
path: req.url
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=22.12.0"
|
||||
"node": ">=20.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "concurrently \"vite\" \"tsx watch src/server/index.ts\"",
|
||||
|
||||
Reference in New Issue
Block a user