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

168
Views
Cors habilitó pero aún recibió este "Origin ha sido bloqueado por la política CORS: No hay encabezado 'Access-Control-Allow-Origin' presente"

Estoy intentando redirigir el navegador desde el backend, pero recibo este error cors cada vez. En el backend, utilicé el paquete CORS, sin embargo, parece que no funcionó.

Aquí está el sitio del cliente del código.

 useEffect(() => { async function getData() { try { // The params get from the url. const { data } = await axios.get(`http://localhost:5000/${url}`); setDestination(data); } catch (error) { setError(error.message); } } getData(); }, [url]); useEffect(() => { if (destination) { window.location.replace(destination); } }, [destination]);

Aquí está el sitio del servidor del código.

 // app.js const express = require("express"); const cors = require("cors"); const app = express(); app.use(express.urlencoded({ extended: false })); app.use(express.json()); app.use(cors()); //redirect controller exports.redirect = asyncErrorHandler(async(req, res, next) => { const shortUrl = await urlSchema.findOne({ shortUrl: req.params.shortUrl }); if (!shortUrl) { return next(new ErrorHandler("Invalid URL", 404)); } const url = shortUrl.fullUrl; res.redirect(url); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El código del lado del servidor que nos ha mostrado, mientras CORS está habilitado, redirige a otra URL.

Al redireccionar tanto la respuesta de redirección como la respuesta a la solicitud posterior debe otorgar permiso con CORS.

No puede engañar al navegador para que le dé a su JavasScript acceso a http://third-party.example.com/ (que no está habilitado para CORS) haciendo una solicitud a http://mine.example.net/ (que is) y redirigir a http://third-party.example.com/ .

about 4 years ago · Juan Pablo Isaza 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!