Jump to content

UM3 API and CORS


frejete

Recommended Posts

Posted · UM3 API and CORS

Hello,

I wanted to write a quick dashboard that would show the video feed, the loaded materials and the printer status (free, printing with completion percentage, need to remove the finished print) for our Ultimaker 3 printer at the office so that everyone can see at a glance what's up without standing up from their desk or launching Cura.

This would be pretty simple with a simple HTML and Javascript webpage but I can't call the API because of CORS restrictions. I don't really want to install a server with a server side script to proxy my calls to the API.

Would it be possible to add unrestricted CORS headers to the API server

Access-Control-Allow-Origin: *

, or have JSONP support?

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    hi frejete,

    All the read information requests should not be locked down or require authentication.

    So a pure information page can be done easily.

    Changing things about the printer will require authentication though.

    We'll want something like this for ourselves as well but then having some login would still be required, we don't want to make an inherently unsecure machine, like some internet of things machines are these days.

    Besides that you can even use the username password prompt you get right now with proper authentication data if you want to... (requires some Linux knowledge or python scripting).

    your browser can save it for you even if it is some unreadable string...

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    CORS with * disables all authentication, and thus breaks our authentication implementation. We could set it for pages that do not require authentication, but that gets a bit more complex pretty fast.

    However, maybe a better deal for all of us. We currently don't have a dashboard implementation scheduled yet. But I do want a landing page. So I wouldn't mind including your dashboard implementation in the next firmware release as just the default landing page.

  • Link to post
    Share on other sites

    • 1 month later...
    Posted · UM3 API and CORS

    A screen with the temperature graph, camera feed, printer status and maybe log data would be ideal. Especially when you have multiple printers that are not close to your desk. All of these things are now scattered over multiple pages and cura.

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    I'm also trying to build a dashboard, in SharePoint, so I don't have the ability to enable CORS on the server. It would be great if the API had the ability to return JSONP to get around this.

  • Link to post
    Share on other sites

    Posted · UM3 API and CORS

    There is a way to add CORS support to the printer without breaking authentication. You do not need to respond with the

    Access-Control-Allow-Origin : *

    header instead you can reply with an Access-Control-Allow-Origin header that copies the request Origin (which will always be provided if it matters for CORS). I added the following code to /usr/share/griffin/griffin/interface/http/server.py and it now allows CORS:

    # At the end of __init__:
    
            # Add CORS support
            self.after_request(Server.allow_cors)
    
    # At the end of Server:
    
        @staticmethod                                           
        def allow_cors(response):                                    
            if "Origin" in flask.request.headers:                                                                                
                response.headers["Access-Control-Allow-Origin"] = flask.request.headers["Origin"]
                response.headers["Vary"] = "Origin"
            return response                              

    Then you have to restart the HTTP server with 

    systemctl restart griffin.interface.http

    or just restart the machine.

     

    It would be nice if this showed up in the next firmware update so we don't have to go into developer mode to do it.

     

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.8 Stable released 🎉
        In the Cura 5.8 stable release, everyone can now tune their Z seams to look better than ever. Method series users get access to new material profiles, and the base Method model now has a printer profile, meaning the whole Method series is now supported in Cura!
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...