aboutsummaryrefslogtreecommitdiff
path: root/api/src/plugins/cors.ts
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/plugins/cors.ts')
-rw-r--r--api/src/plugins/cors.ts18
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;