Message ID | 1519650566-8487-1-git-send-email-sami.hartikainen@teleste.com |
---|---|
State | Changes Requested |
Headers | show |
Series | www: web-app: Formulate URIs to be reverse proxy -friendly | expand |
Hi Sami, Am 26.02.2018 um 14:09 schrieb Sami Hartikainen: > Define the /ws and /upload URIs in a way that allows reverse proxy > to pass configured service URIs to the SWUpdate webserver listening > port. > > This makes e.g. the following Nginx location functional: > > location /swupdate/ { > < other settings ...> > proxy_pass http://127.0.0.1:8080/; > } > > Signed-off-by: Sami Hartikainen <sami.hartikainen@teleste.com> > --- > web-app/index.html | 2 +- > web-app/js/swupdate.js | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > [snip] > diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js > index f89b47d..172d52e 100755 > --- a/web-app/js/swupdate.js > +++ b/web-app/js/swupdate.js > @@ -117,7 +117,7 @@ window.onload = function () { > > if (window.location.protocol === 'https:') { protocol = 'wss:' } else { protocol = 'ws:' } > > - var ws = new WebSocket(protocol + '//' + window.location.host + '/ws') > + var ws = new WebSocket(protocol + '//' + window.location.host + window.location.pathname.replace(/\/$/, '') + '/ws') What happens if the pathname includes the index.html? Best regards Stefan
Hi Stefan, >> diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js index >> f89b47d..172d52e 100755 >> --- a/web-app/js/swupdate.js >> +++ b/web-app/js/swupdate.js >> @@ -117,7 +117,7 @@ window.onload = function () { >> >> if (window.location.protocol === 'https:') { protocol = 'wss:' } >> else { protocol = 'ws:' } >> >> - var ws = new WebSocket(protocol + '//' + window.location.host + >> '/ws') >> + var ws = new WebSocket(protocol + '//' + window.location.host + >> + window.location.pathname.replace(/\/$/, '') + '/ws') >What happens if the pathname includes the index.html? The resulting URL looks quite silly. But the application (i.e. WebSocket communication) still works; as long as the websocket connection reaches the webserver, the actual URL does not matter. WebSocket connection headers look like this: General Request URL:ws://192.168.230.106/swupdate/index.html/ws Request Method:GET Status Code:101 Switching Protocols Response Headers Connection:upgrade Date:Tue, 27 Feb 2018 07:43:01 GMT Sec-WebSocket-Accept:5fbRiNpjC6+MME5ZgmXBuhjWvOM= Server:nginx/1.10.3 Upgrade:websocket Request Headers Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.9 Cache-Control:no-cache Connection:Upgrade Host:192.168.230.106 Origin:http://192.168.230.106 Pragma:no-cache Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits Sec-WebSocket-Key:QPgTlV3CFypyb8IdwoRa2w== Sec-WebSocket-Version:13 Upgrade:websocket User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36 Br, Sami
Hi Sami, Am 27.02.2018 um 09:18 schrieb Sami.Hartikainen@teleste.com: >>> diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js index >>> f89b47d..172d52e 100755 >>> --- a/web-app/js/swupdate.js >>> +++ b/web-app/js/swupdate.js >>> @@ -117,7 +117,7 @@ window.onload = function () { >>> >>> if (window.location.protocol === 'https:') { protocol = 'wss:' } >>> else { protocol = 'ws:' } >>> >>> - var ws = new WebSocket(protocol + '//' + window.location.host + >>> '/ws') >>> + var ws = new WebSocket(protocol + '//' + window.location.host + >>> + window.location.pathname.replace(/\/$/, '') + '/ws') >> What happens if the pathname includes the index.html? > The resulting URL looks quite silly. But the application (i.e. WebSocket communication) still > works; as long as the websocket connection reaches the webserver, the actual URL does not > matter. You are right and maybe this should be fixed in the mongoose implementation. I would prefer if we remove everything behind the last slash from the pathname. Does the following always works? window.location.pathname.replace(/\/[^\/]*$/ , '') + '/ws' Best regards Stefan
Hi Stefan, > >>> - var ws = new WebSocket(protocol + '//' + window.location.host + > >>> '/ws') > >>> + var ws = new WebSocket(protocol + '//' + window.location.host + > >>> + window.location.pathname.replace(/\/$/, '') + '/ws') > >> What happens if the pathname includes the index.html? > > The resulting URL looks quite silly. But the application (i.e. > > WebSocket communication) still works; as long as the websocket > > connection reaches the webserver, the actual URL does not matter. > > You are right and maybe this should be fixed in the mongoose > implementation. > > I would prefer if we remove everything behind the last slash from the > pathname. > > Does the following always works? > > window.location.pathname.replace(/\/[^\/]*$/ , '') + '/ws' Yes it does, and results in much nicer URLs. Updated patch follows... Br, Sami
diff --git a/web-app/index.html b/web-app/index.html index f7bfe94..cca5029 100755 --- a/web-app/index.html +++ b/web-app/index.html @@ -62,7 +62,7 @@ </div> <div class="card-body"> <!-- Dropzone Button for drag&drop files --> - <form class="dropzone border rounded mb-3" id="dropzone" action="/upload" method="post" enctype="multipart/form-data"> + <form class="dropzone border rounded mb-3" id="dropzone" action="./upload" method="post" enctype="multipart/form-data"> <div class="dz-default dz-message"> <span class="dz-message">Click hier or drop a software update image.</span> </div> diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js index f89b47d..172d52e 100755 --- a/web-app/js/swupdate.js +++ b/web-app/js/swupdate.js @@ -117,7 +117,7 @@ window.onload = function () { if (window.location.protocol === 'https:') { protocol = 'wss:' } else { protocol = 'ws:' } - var ws = new WebSocket(protocol + '//' + window.location.host + '/ws') + var ws = new WebSocket(protocol + '//' + window.location.host + window.location.pathname.replace(/\/$/, '') + '/ws') ws.onopen = function (event) { updateStatus('IDLE')
Define the /ws and /upload URIs in a way that allows reverse proxy to pass configured service URIs to the SWUpdate webserver listening port. This makes e.g. the following Nginx location functional: location /swupdate/ { < other settings ...> proxy_pass http://127.0.0.1:8080/; } Signed-off-by: Sami Hartikainen <sami.hartikainen@teleste.com> --- web-app/index.html | 2 +- web-app/js/swupdate.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)