import { FastifyInstance } from "fastify";
import fp from "fastify-plugin";
import cors from "@fastify/cors";

export default fp(async (server: FastifyInstance) => {
    await server.register(cors, {
        origin: [
            "http://localhost:3000", // dein Nuxt-Frontend
            "http://localhost:3001", // dein Nuxt-Frontend
            "http://127.0.0.1:3000", // dein Nuxt-Frontend
            "http://192.168.1.227:3001", // dein Nuxt-Frontend
            "http://192.168.1.234:3000", // dein Nuxt-Frontend
            "http://192.168.1.113:3000", // dein Nuxt-Frontend
            "https://beta.fedeo.de", // dein Nuxt-Frontend
            "https://app.fedeo.de", // dein Nuxt-Frontend
            "capacitor://localhost", // dein Nuxt-Frontend
        ],
        methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS","PATCH",
            "PROPFIND", "PROPPATCH", "MKCOL", "COPY", "MOVE", "LOCK", "UNLOCK"],
        allowedHeaders: ["Content-Type", "Authorization", "Context", "X-Public-Pin","Depth", "Overwrite", "Destination", "Lock-Token", "If"],
        exposedHeaders: ["Authorization", "Content-Disposition", "Content-Type", "Content-Length"], // optional, falls du ihn auch auslesen willst
        credentials: true, // wichtig, falls du Cookies nutzt
    });
});