From 80b78bb35e778bbc8c4f581a98092cdfb75c7d50 Mon Sep 17 00:00:00 2001 From: edpomacedo Date: Wed, 27 Dec 2023 23:15:06 -0300 Subject: [PATCH] bug fix --- functions/index.ts | 14 ++++++--- package-lock.json | 78 +++++++++++++--------------------------------- package.json | 3 +- 3 files changed, 32 insertions(+), 63 deletions(-) diff --git a/functions/index.ts b/functions/index.ts index 82861c2..dddd4c5 100644 --- a/functions/index.ts +++ b/functions/index.ts @@ -1,5 +1,5 @@ import { FastifyInstance, FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify'; -import fastifyCors from 'fastify-cors'; +import fastifyCors, { FastifyCorsOptions } from '@fastify/cors'; import axios from 'axios'; interface IQueryString { @@ -11,12 +11,16 @@ interface CustomRouteGenericQuery { } export default async function (instance: FastifyInstance, opts: FastifyServerOptions, done) { - // Register @fastify/cors plugin - instance.register(fastifyCors, { - origin: '*', + // Define your CORS options + const corsOptions: FastifyCorsOptions = { + origin: '*', // You can customize this based on your requirements methods: ['GET', 'POST'], allowedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept'], - }); + // Add other CORS options as needed + }; + + // Register @fastify/cors plugin with the defined options + instance.register(fastifyCors, corsOptions); instance.get('/', async (req: FastifyRequest, res: FastifyReply) => { res.status(200).send('Bem-vindo à sua aplicação FastAPI!'); diff --git a/package-lock.json b/package-lock.json index dd4d29c..9243981 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,13 +9,12 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@fastify/cors": "^7.0.0", + "@fastify/cors": "^8.5.0", "axios": "^1.6.3", "dotenv": "^16.3.1", "fastify": "^4.25.2" }, "devDependencies": { - "@types/fastify-cors": "^2.1.0", "@vercel/node": "^3.0.14" } }, @@ -111,12 +110,12 @@ } }, "node_modules/@fastify/cors": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-7.0.0.tgz", - "integrity": "sha512-nlo6ScwagBNJacAZD3KX90xjWLIoV0vN9QqoX1wUE9ZeZMdvkVkMZCGlxEtr00NshV0X5wDge4w5rwox7rRzSg==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-8.5.0.tgz", + "integrity": "sha512-/oZ1QSb02XjP0IK1U0IXktEsw/dUBTxJOW7IpIeO8c/tNalw/KjoNSJv1Sf6eqoBPO+TDGkifq6ynFK3v68HFQ==", "dependencies": { - "fastify-plugin": "^3.0.0", - "vary": "^1.1.2" + "fastify-plugin": "^4.0.0", + "mnemonist": "0.39.6" } }, "node_modules/@fastify/deepmerge": { @@ -266,16 +265,6 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, - "node_modules/@types/fastify-cors": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@types/fastify-cors/-/fastify-cors-2.1.0.tgz", - "integrity": "sha512-o01k3tVq/6kNDv2Q+STSHOsgRPD1jEL5kzhBp6RFu0VSHdyUW6WnOctuS1gC9mdlZyuldGR0Eo8vdkP8ZrPa8g==", - "deprecated": "This is a stub types definition. fastify-cors provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "fastify-cors": "*" - } - }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1299,38 +1288,10 @@ "toad-cache": "^3.3.0" } }, - "node_modules/fastify-cors": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/fastify-cors/-/fastify-cors-6.1.0.tgz", - "integrity": "sha512-QBKz32IoY/iuT74CunRY1XOSpjSTIOh9E3FxulXIBhd0D2vdgG0kDvy0eG6HA/88sRfWHeba43LkGEXPz0Rh8g==", - "deprecated": "Please use @fastify/cors@7.0.0 instead", - "dev": true, - "dependencies": { - "fastify-cors-deprecated": "npm:fastify-cors@6.0.3", - "process-warning": "^1.0.0" - } - }, - "node_modules/fastify-cors-deprecated": { - "name": "fastify-cors", - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/fastify-cors/-/fastify-cors-6.0.3.tgz", - "integrity": "sha512-fMbXubKKyBHHCfSBtsCi3+7VyVRdhJQmGes5gM+eGKkRErCdm0NaYO0ozd31BQBL1ycoTIjbqOZhJo4RTF/Vlg==", - "dev": true, - "dependencies": { - "fastify-plugin": "^3.0.0", - "vary": "^1.1.2" - } - }, - "node_modules/fastify-cors/node_modules/process-warning": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-1.0.0.tgz", - "integrity": "sha512-du4wfLyj4yCZq1VupnVSZmRsPJsNuxoDQFdCFHLaYiEbFBD7QE0a+I4D7hOxrVnh78QE/YipFAj9lXHiXocV+Q==", - "dev": true - }, "node_modules/fastify-plugin": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz", - "integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==" + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-4.5.1.tgz", + "integrity": "sha512-stRHYGeuqpEZTL1Ef0Ovr2ltazUT9g844X5z/zEBFLG8RYlpDiOCIG+ATvYEp+/zmc7sN29mcIMp8gvYplYPIQ==" }, "node_modules/fastq": { "version": "1.16.0", @@ -1784,6 +1745,14 @@ "node": ">=10" } }, + "node_modules/mnemonist": { + "version": "0.39.6", + "resolved": "https://registry.npmjs.org/mnemonist/-/mnemonist-0.39.6.tgz", + "integrity": "sha512-A/0v5Z59y63US00cRSLiloEIw3t5G+MiKz4BhX21FI+YBJXBOGW0ohFxTxO08dsOYlzxo87T7vGfZKYp2bcAWA==", + "dependencies": { + "obliterator": "^2.0.1" + } + }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", @@ -1865,6 +1834,11 @@ "node": ">=0.10.0" } }, + "node_modules/obliterator": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz", + "integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==" + }, "node_modules/on-exit-leak-free": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", @@ -2440,14 +2414,6 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, - "node_modules/vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", diff --git a/package.json b/package.json index 43ddd56..eec4e21 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,12 @@ "author": "@edpomacedo", "license": "ISC", "dependencies": { - "@fastify/cors": "^7.0.0", + "@fastify/cors": "^8.5.0", "axios": "^1.6.3", "dotenv": "^16.3.1", "fastify": "^4.25.2" }, "devDependencies": { - "@types/fastify-cors": "^2.1.0", "@vercel/node": "^3.0.14" } }