Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
edpomacedo committed Dec 28, 2023
1 parent f06cab6 commit 80b78bb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 63 deletions.
14 changes: 9 additions & 5 deletions functions/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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!');
Expand Down
78 changes: 22 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 80b78bb

Please sign in to comment.