Search code examples
reactjswebserverproduction

React app production with Apache on Alwaysdata


I have an app ReactJS in production mode on my apache web server, but I load it in user program (Only react), we can see source code.

I can use Apache but when I do, it override all other site on the same domain (*.example.com) with that conf:

DocumentRoot /home/neko/www/react/build
<Directory "/home/neko/www/react/build">
    RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]
  </Directory>

Edit: On alwaysdata we doesn't need to set virtualhost braquet
So that config work but we can see source code anyway


Solution

  • The solution was to use Webpack, that tutoriel help me a lot.

    At final, webpack create us a folder named dist with just index.html and main.js and that can be use like that on my web server.
    So it can be like that (On Alwaysdata):

    DocumentRoot /home/neko/www/react/dist
    <Directory "/home/neko/www/react/dist">
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]
        RewriteRule ^ index.html [L]
      </Directory>