Files
calendar/packages/trpc/server/routers/publicViewer/countryCode.handler.ts
T
2024-01-15 09:51:16 +00:00

16 lines
487 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { CreateInnerContextOptions } from "../../createContext";
type CountryCodeOptions = {
ctx: CreateInnerContextOptions;
};
export const countryCodeHandler = async ({ ctx }: CountryCodeOptions) => {
const { req } = ctx;
const countryCode: string | string[] =
req?.headers?.["cf-ipcountry"] ?? req?.headers?.["x-vercel-ip-country"] ?? "";
return { countryCode: Array.isArray(countryCode) ? countryCode[0] : countryCode };
};
export default countryCodeHandler;