Skip to content

Request: Add CORS header config to demo.mtconnect.org agent #506

Open

Description

@robot-ranger

Is it possible to add the CORS header config (https://github.com/mtconnect/cppagent?tab=readme-ov-file#rest-service-configuration) to the demo agent at https://demo.mtconnect.org/probe?

Im am working on browser-based client and getting CORS errors trying to get response docs. It is working against my local agent (that does have the above CORS config applied), but I would like to test against an "unknown" device model.

Activity

  1. robot-ranger commented on Dec 6, 2024

    @robot-ranger
    CollaboratorAuthor

    for what its worth, we plan on opening up this client in a public repo. Gotta be functional first, though.

  2. robot-ranger commented on May 10, 2026

    @robot-ranger
    CollaboratorAuthor

    @wsobel I assumed the agent running at demo.mtconnect.org referenced the file I comitted to close this issue, but im still getting CORS denials when connecting to demo.mtconnect.org from a browser webapp.

    cli apps connect fine - i believe this is only relevant for browser-based webapp clients.

    are you willing to open up the CORS on demo.mtconnect.org to allow for browser webapp demonstration?

  3. wsobel commented on May 10, 2026

    @wsobel
    Member

    The demo agent is running using the docker compose demo and has nginx with reverse proxy. I'll check if they are passing through the CORS preflight and OPTIONS. I thought it should be working. I may need to add
    extra headers as well.

    Please tell me what you're trying to do with CORS and what's not working.I may need to just patch the nginx config or the cfg file for additional headers.

  4. robot-ranger commented on May 10, 2026

    @robot-ranger
    CollaboratorAuthor

    for context, I had previously transcribed the client used in the digital twin demo to typescript: https://github.com/processrobotics/mtconnect-ts/blob/main/src/MTConnect.ts

    I am trying to use the probe() method from my lib above, but the browser shows:

    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://demo.mtconnect.org:5000/probe. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS/Errors/CORSMissingAllowOrigin

    the same webapp works fine wen directed to my local agents, albeit those are configured to allow all with the following in agent.json:

    "HttpHeaders": {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET",
            "Access-Control-Allow-Headers": "Accept"
        },
  5. robot-ranger commented on May 10, 2026

    @robot-ranger
    CollaboratorAuthor

    side note: i get 301: Moved Permanently when i omit port 5000 in the url:
    request header without port 5000:

    GET /probe HTTP/1.1
    Host: demo.mtconnect.org
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
    Accept: application/json
    Accept-Language: en-US,en;q=0.9
    Accept-Encoding: gzip, deflate
    Referer: http://localhost:5173/
    Origin: http://localhost:5173
    Connection: keep-alive
    Sec-GPC: 1
    Priority: u=4
    

    response header without port 5000:

    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.18.0 (Ubuntu)
    Date: Sun, 10 May 2026 21:47:25 GMT
    Content-Type: text/html
    Content-Length: 178
    Connection: keep-alive
    Location: https://demo.mtconnect.org/probe
    

    request header WITH port 5000 in url:

    GET /probe HTTP/1.1
    Host: demo.mtconnect.org:5000
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
    Accept: application/json
    Accept-Language: en-US,en;q=0.9
    Accept-Encoding: gzip, deflate
    Referer: http://localhost:5173/
    Origin: http://localhost:5173
    Connection: keep-alive
    Sec-GPC: 1
    Priority: u=4
    

    response header WITH port 5000 in url:

    HTTP/1.1 200 OK
    Server: MTConnectAgent
    Date: Sun, 10 May 2026 21:49:56 GMT
    Expires: -1
    Cache-Control: no-store, max-age=0
    Content-Type: application/mtconnect+json
    Content-Length: 43320
    
  6. robot-ranger commented on May 10, 2026

    @robot-ranger
    CollaboratorAuthor

    well i just noticed that firefox actually gets a 200 OK response, and it DOES get the response doc content. but then blocks it from being used in scripts locally due to CORS?!

    Image
  7. wsobel commented on May 10, 2026

    @wsobel
    Member

    I'll check it out tomorrow. Port 5000 is supposed to be blocked, but oops. Nothing too bad,just bypassing nginx. I'll check the headers and make sure cross scripting is enabled. I can also now allow GET and OPTIONS methods.

  8. robot-ranger commented on May 11, 2026

    @robot-ranger
    CollaboratorAuthor

    Does the agent at demo.mtconnect.org allow/support websocket?

    its been in my mind to start moving toward websocket over http... if the demo.mtconnect.org has ws maybe now is as good a time as any...

  9. wsobel commented on May 11, 2026

    @wsobel
    Member

    It should work. The agent supports websockets and if something doesn't work, it would be a change to nginx to pass wesocket request through to the agent.

    Tell me if you have issues. I'll get to this tomorrow.

  10. robot-ranger commented on May 11, 2026

    @robot-ranger
    CollaboratorAuthor

    no immediate rush. our webapp works on our local agents, i just wanted to pressure test it a bit with an "unknown" agent and devices model.

  11. wsobel commented on May 12, 2026

    @wsobel
    Member

    I added the header:

    $  StandardsCommittee curl -I -X OPTIONS https://demo.mtconnect.org/probe
    HTTP/1.1 204 No Content
    Server: nginx/1.18.0 (Ubuntu)
    Date: Tue, 12 May 2026 18:42:45 GMT
    Content-Type: text/plain
    Content-Length: 0
    Connection: keep-alive
    Expires: -1
    Cache-Control: no-store, max-age=0
    Access-Control-Allow-Origin: *
    Allow: GET, OPTIONS
    Access-Control-Allow-Methods: GET, OPTIONS
    Access-Control-Allow-Headers: Content-Type, Accept, Accept-Encoding
    Access-Control-Max-Age: 86400

    and

    ➜  StandardsCommittee curl -i https://demo.mtconnect.org/
    HTTP/1.1 200 OK
    Server: nginx/1.18.0 (Ubuntu)
    Date: Tue, 12 May 2026 18:47:36 GMT
    Content-Type: application/xml
    Content-Length: 46372
    Connection: keep-alive
    Expires: -1
    Cache-Control: no-store, max-age=0
    Access-Control-Allow-Origin: *

    Check if that helps. I can add additional headers if necessary.

    I may need to add Access-Control-Allow-Headers: Origin, Content-Type, Accept, Accept-Encoding to the allow headers line. I can modify if necessary.

    btw. I did not modify nginx, this is all coming directly from the agent.

  12. reopened this on May 12, 2026
  13. robot-ranger commented on May 14, 2026

    @robot-ranger
    CollaboratorAuthor

    seems to work now as long as im using https

  14. wsobel commented on May 14, 2026

    @wsobel
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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