28 lines
917 B
TypeScript
28 lines
917 B
TypeScript
import type { NextApiRequest, NextApiResponse } from "next"
|
|
import { optimizeDatabase, getDatabaseStats } from "../../../lib/db-optimizations"
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (req.method === "POST") {
|
|
try {
|
|
await optimizeDatabase()
|
|
res.json({
|
|
success: true,
|
|
message: "Database optimized successfully",
|
|
optimized_at: new Date().toISOString()
|
|
})
|
|
} catch (error) {
|
|
console.error('Optimization error:', error)
|
|
res.status(500).json({ error: "Optimization failed" })
|
|
}
|
|
} else if (req.method === "GET") {
|
|
try {
|
|
const stats = await getDatabaseStats()
|
|
res.json(stats)
|
|
} catch (error) {
|
|
console.error('Stats error:', error)
|
|
res.status(500).json({ error: "Failed to get database stats" })
|
|
}
|
|
} else {
|
|
res.status(405).json({ error: "Method not allowed" })
|
|
}
|
|
} |