diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-08-16 23:17:42 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-08-16 23:17:42 +0000 |
| commit | 375482e654a01615683867e732ac9e458c7cbe74 (patch) | |
| tree | 12d1b31b8deb6bf8590bcdbc2cfb52dcc553e006 /api/src/plugins/cors.ts | |
| parent | 2c2dfba45357bbd205a59145ae55a2779c911ae0 (diff) | |
| download | yaba-375482e654a01615683867e732ac9e458c7cbe74.tar.gz yaba-375482e654a01615683867e732ac9e458c7cbe74.zip | |
Signed-off-by: Lucas Faria Mendes <lucas.fariamo08@gmail.com>
Diffstat (limited to 'api/src/plugins/cors.ts')
| -rw-r--r-- | api/src/plugins/cors.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/api/src/plugins/cors.ts b/api/src/plugins/cors.ts new file mode 100644 index 0000000..5398e39 --- /dev/null +++ b/api/src/plugins/cors.ts @@ -0,0 +1,18 @@ +import cors from '@fastify/cors'; +import type { FastifyPluginAsync } from 'fastify'; + +/** + * Plugin de CORS para o Fastify. + * Em produção, substitua o `origin: true` pelo domínio/IP do seu app mobile + * ou pelo endereço da sua VPS. + */ +const corsPlugin: FastifyPluginAsync = async (fastify) => { + fastify.register(cors, { + // Em dev: aceita qualquer origem + // Em prod: restrinja para o IP/domínio conhecido + origin: process.env.CORS_ORIGIN ?? true, + methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], + }); +}; + +export default corsPlugin; |