Skip to content

CORS errors #1

@gobengo

Description

@gobengo

When I access peoplesopen-dash on my home node using a DNS name, it doesn't work. It appears to be because the webapp UI is making requests to http://172.30.0.1/cgi-bin/infogather . These requests are blocked by the browser because that web service doesn't allow this 'Origin' via the proper CORS headers.

Failed to load http://172.30.0.1/cgi-bin/infogather: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I get this error when accessing:

  • via https://admin.peoplesopen.net while connected to my home node
  • when running peoplesopen-dash locally via npm start, and accessing via both http://127.0.0.1:3000/ and http://localhost:3000/

What serves that endpoint on the home node itself? Is it easy for us to add the required CORS response headers? Or perhaps run an http proxy that will do CORS as needed without changing the underlying /infogather app.

--

Workaround: Run your own CORS proxy alongside peoplesopen-dash:

  • npm install -g corsproxy
  • corsproxy to run corsproxy at default baseUrl of http://localhost:1337 (see README to configure port/host)
  • change peoplesopen-dash/src/config.js (note localhost:1337/ prefix):
    export default {
      ubusUrl: 'http://localhost:1337/172.30.0.1/ubus',
      infogatherUrl: 'http://localhost:1337/172.30.0.1/cgi-bin/infogather',
      username: 'admin'
    }
  • use http://localhost:3000 as normal. This app will request the home node through the corsproxy, which will add the appropriate Access-Control-Allow-* headers such that the browser doesn't block AJAX requests from the frontend

Future Work:

  • Because npm, it would be quite reasonable for peoplesopen-dash's process to do corsproxy-like stuff on some sub-route. However, because we're delegating all that to react-scripts start, I'm not sure how to add that capability
    • There are pluses and minuses to 'ejecting' from create-react-app. Anyone opposed to ejecting at some point (maybe not now)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions