Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

414
Vistas
Uncaught SyntaxError: Unexpected end of input, Error while decoupling drupal 9 with react as front end

I am trying to implement the decoupled react and Drupal , in which i am trying use Drupal as backend and react as front end, when i try get a response it comes , but when i am convert the response in json , it gives me the error Uncaught (in promise) SyntaxError: Unexpected end of input , so how should i solve it?

React code ->

  import React, { useState, useEffect } from "react";
  const Exampleno2 = () => {
  const [posts, setPosts] = useState([]);
  var myHeaders = new Headers();
  myHeaders.append("Accept", " application/vnd.api+json");
  myHeaders.append("Content-Type", "application/vnd.api+json");

  var requestOptions = {
    method: "GET",
    headers: myHeaders,
    redirect: "follow",
  };
  const fetchPost = async () => {
    const response = await fetch(
      "http://localhost/drupalwebsite/jsonapi/node/banner",
      { mode: "no-cors" },
      requestOptions
    );
    console.log(response);
    const data = await response.json();
    console.log(data)
    };
    useEffect(() => {
    fetchPost();
    }, []);
  return (
    <div>
      <h1>hello</h1>
    </div>
  );
};

export default Exampleno2;

This is Drupal backend service.yml file code->

cors.config:
  enabled: true
  # Specify allowed headers, like 'x-allowed-header'.
  allowedHeaders: [ '*','accept','application/vnd.api+json', 'access-control-allow-origin' ]
  # Specify allowed request methods, specify ['*'] to allow all possible ones.
  allowedMethods: [ '*' ]
  # Configure requests allowed from specific origins.
  allowedOrigins: [ 'http://localhost/','http://localhost:3000','http://localhost:3001','http://localhost:3002','*' ]
  # Sets the Access-Control-Expose-Headers header.
  exposedHeaders: false
  # Sets the Access-Control-Max-Age header.
  maxAge: false
  # Sets the Access-Control-Allow-Credentials header.
  supportsCredentials: true 

i don't understand what did i do wrong in the code 😅? pls somebody help me 😥?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda