You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
991 B

  1. import { NextResponse } from 'next/server';
  2. import { revalidatePath } from 'next/cache'; // ADD THIS
  3. import { getPortals, savePortals } from '@/lib/db';
  4. import { Portal } from '@/types';
  5. export const dynamic = 'force-dynamic';
  6. export async function GET() {
  7. const portals = await getPortals();
  8. return NextResponse.json(portals[0] || null);
  9. }
  10. export async function POST(request: Request) {
  11. try {
  12. const incomingPortal: Portal = await request.json();
  13. const portals = await getPortals();
  14. if (portals.length > 0) {
  15. portals[0] = { ...portals[0], ...incomingPortal };
  16. } else {
  17. portals.push({ ...incomingPortal, id: 'default-portal', tenantId: 'default' });
  18. }
  19. await savePortals(portals);
  20. // ADD THIS LINE
  21. revalidatePath('/');
  22. return NextResponse.json(portals[0], { status: 200 });
  23. } catch (error) {
  24. return NextResponse.json({ error: 'Failed to save portal settings' }, { status: 500 });
  25. }
  26. }