Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
¿Cómo usar fastify-cors para habilitar solo una API para cruzar dominios?

Quiero permitir que [POST] localhost/product solo esta API entre dominios.

no se como hacerlo

 fastify.register(require('fastify-cors'), { origin:'*', methods:['POST'], })

esta es mi API:

 { method: 'POST', url: '/product', handler: productsController.addProduct, },
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En este caso, no se requiere una dependencia externa. En su lugar, configure los encabezados CORS manualmente en productsController.addProduct .

Ejemplo de manipulación manual del encabezado CORS:

 function addProduct(request, reply) { reply.header("Access-Control-Allow-Origin", "*"); reply.header("Access-Control-Allow-Methods", "POST"); // ... more code here ... }

Si aún desea usar fastify-cors , intente algo como esto:

 fastify.register((fastify, options, done) => { fastify.register(require("fastify-cors"), { origin: "*", methods: ["POST"] }); fastify.route({ method: "POST", url: "/product", handler: productsController.addProduct }); done(); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!