Giter VIP home page Giter VIP logo

Comments (4)

tmotyl avatar tmotyl commented on July 21, 2024

How is your middleware implemented in a way it doesnt interfere with other sites where headles might not be used thus text/html would be correct?

from headless.

schloram avatar schloram commented on July 21, 2024

Well, we use headless for the whole TYPO3 instance. But I see your point. Tricky. :D

from headless.

Moongazer avatar Moongazer commented on July 21, 2024

What is your recommend way to handle 404, 403 and other errors with headless?
So far only HTML is returned instead of a JSON error response object.

My idea was to evaluate the response-status codes inside the frontend to handle the errors, unfortunately this does not work for multiple reasons if CORS comes into play.

Because the Frontend-App and API are served under different domains, I set the CORS header in TypoScript:

config {
  additionalHeaders {
    50.header = Access-Control-Allow-Origin: http://my-javascript-frontend.net
    51.header = Access-Control-Allow-Credentials: true
  }
}

This works good for all successful requests (status 200). But for error responses, the CORS header are not set. This leads the browser to blocking the XHR request, so the frontend is not even able to validate the response status code.

Access to XMLHttpRequest at 'https://api.my-typo3-headless.net/login/private-page' from origin 'http://my-javascript-frontend.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

from headless.

lukaszuznanski avatar lukaszuznanski commented on July 21, 2024

Duplicate of #202, please reopen if you have any other issues.

from headless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.