Hi, I’m Dung Huynh Duc . Nice to meet you.

About Me

With over a decade of experience under my belt as a full-stack developer, I've had the opportunity to spearhead project teams at tech startups in Vietnam, Thailand, Japan and Singapore. Additionally, I have worked as a freelance engineer for various companies based in Asia Pacific, Europe, and North America.

Presently, I serve the role of a Senior Full Stack Software Engineer at ACX. I am consistently committed to exploring and acquiring knowledge on emerging and popular technologies.

fastify
trpc

#TIL 24 - Workaround for tRPC Fastify adatper CORS policy

blog_hero_#TIL 24 - Workaround for tRPC Fastify adatper CORS policy
void app.register(fp(fastifyTRPCPlugin), {
  prefix: "/trpc",
  trpcOptions: {
    router: appRouter,
    createContext,
    responseMeta(opts: any) {
      if (
        opts.errors?.[0]?.code === "METHOD_NOT_SUPPORTED" &&
        String(opts.errors?.[0]?.message ?? "").includes(
          "Unexpected request method OPTIONS"
        )
      ) {
        return {
          status: 204,
          headers: {
            "Access-Control-Allow-Headers": "Content-Type",
            "access-control-allow-origin": "*",
            vary: "Origin",
          },
        };
      }

      return {
        // Enable CORS, refer https://github.com/trpc/trpc/issues/623#issuecomment-878639248
        headers: {
          "Access-Control-Allow-Headers": "Content-Type",
          "access-control-allow-origin": "*",
          vary: "Origin",
        },
      };
    },
  },
});