diff mbox series

[v2] www: web-app: Formulate URIs to be reverse proxy -friendly

Message ID 1519827651-9987-1-git-send-email-sami.hartikainen@teleste.com
State Accepted
Headers show
Series [v2] www: web-app: Formulate URIs to be reverse proxy -friendly | expand

Commit Message

Hartikainen, Sami Feb. 28, 2018, 2:20 p.m. UTC
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(-)

Comments

Stefano Babic March 2, 2018, 11:21 a.m. UTC | #1
Hi Sami,

On 28/02/2018 15:20, Sami Hartikainen wrote:
> 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(-)
> 
> 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..34f3e3e 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')
> 

You and Stefan have already reviewed and fixed this patch. Fine with me,
I am applying it.

Best regards,
Stefano Babic
diff mbox series

Patch

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..34f3e3e 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')