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

407
Views
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
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!