Publish a ReactJs app behind HaProxy (in a subpath)

How to configure a React app to be served from a subpath in HaProxy
haproxy reactjs tech

Publish a ReactJs app behind HaProxy (in a subpath)

I started with the intent of deploying directly a ReactJS app embedded in a tomcat container behind HaProxy. As it turns out, it is terribly difficult (even possible at all ?) to have it behind a HaProxy and in a subpath.

Apache backend server

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# Fallback all other routes to index.html
RewriteRule ^ /react/index.html [L]

That means: whenever I type something in the browser bar that resembles something different from the index.html page, I get redirected to the same index.html. I can actually put those directives in the .htaccess in the root of my application. To make sure this .htaccess file get read, my apache domain config will look somewhat like this:

Listen 10091
<VirtualHost *:10091>
    ServerName kevwe.se
    ServerAlias www.kevwe.se
    DocumentRoot /var/www/kevwe.se

<Directory "/var/www/kevwe.se/react">
    AllowOverride All
</Directory>

My ReactJs application will be deployed in the directory: /var/www/kevwe.se/react , that goes without saying.

ReactJs configuration

In my React application, I need to be aware of the fact that I am going to deploy to a subdir, in two places:

  <BrowserRouter basename='/react/'>
        <div className="App">
          <MainRouter />
        </div>
      </BrowserRouter>
  "homepage": "https://kevwe.se/react/",

HaProxy front-end

If I were to open the 10091 port to the world, I would be done, but that’s not what I want, because I want to use HaProxy for TLS termination. That’s my haproxy config for it:

backend be_apache_kevwe
        server static 127.0.0.1:10091 check
[..]

frontend fe_blackcheck
    acl url_black path_beg /blackcheck
    bind <my-ip-address>:443 ssl crt /etc/haproxy/kevwe.se/certificate.concat
    default_backend be_apache_kevwe

How to delete all local Docker instances

Have you filled your disk because of Docker instances ?
docker linux tech

How to delete all local Docker images

Have you ever filled your disk because of Docker images ?
docker linux tech

Java text blocks as preview in Jdk 13

Java 13
java jdk jdk13 tech