import cors from "@fastify/cors";
import fp from "fastify-plugin";
export const corsPlugin = fp(async function (fastify, opts) {
    fastify.register(cors, () => {
        return (req, callback) => {
            const corsOptions = {
                origin: opts.origin,
            };
            if (/^localhost$/m.test(req.headers.origin ?? "")) {
                corsOptions.origin = false;
            }
            callback(null, corsOptions);
        };
    });
});
//# sourceMappingURL=cors-plugin.js.map