moqui / moqui-framework

Use Moqui Framework to build enterprise applications based on Java. It includes tools for databases (relational, graph, document), local and web services, web and other UI with screens and forms, security, file/resource access, scripts, templates, l10n, caching, logging, search, rules, workflow, multi-instance, and integration.
http://www.moqui.org
Other
281 stars 201 forks source link

javacript error with WebSocket and https #177

Closed locnguyenx closed 7 years ago

locnguyenx commented 7 years ago

When deploy Moqui using https, I got this error in javascript console:

WebSocket connection to 'ws://localhost:8443/notws' failed: Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE

I've checked and found problematic code in apps.xml:

<render-mode><text type="html"><![CDATA[<script>var notificationClient = new moqui.NotificationClient("ws://${ec.web.getHostName(true)}${ec.web.servletContext.contextPath}/notws");</script>]]></text></render-mode>

In fact, I don't know much about WebSocket, so I'm not sure if this error is critical or not. However, after research about this problem, I changed to code below and no error occured:

<render-mode><text type="html"><![CDATA[<script>
        var wsProtocal = "ws";
        if (location.protocol === 'https:') {
            wsProtocal = "wss";
        }
        var notificationClient = new moqui.NotificationClient(wsProtocal + "://${ec.web.getHostName(true)}${ec.web.servletContext.contextPath}/notws");</script>]]></text></render-mode>
jonesde commented 7 years ago

Thank you for bringing this up, a similar improvement is in place in moqui-runtime commit #74b494b (this is really a moqui-runtime thing, as a general guideline there is nothing for websocket client or other web client UI stuff in moqui-framework).