2

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

Tryliom
  • 895
  • 1
  • 12
  • 37
  • What is the question you want answered? – Adam Berman Jul 11 '18 at 05:25
  • How to configure apache with reactjs with the result that we cannot see source code of it – Tryliom Jul 11 '18 at 09:17
  • In Which folder is your source code kept? – Vinod Sai Jul 11 '18 at 14:37
  • I have resolve my problem myself, the build that we obtain with `react-scripts build` allow anyone to see source code as I see it. I build now with webpack, it give me just a main.js and index.html, the source code is safe with that. (In my question, I say source code as the possibility of see all code perfectly, with all modules and other things while the build folder on the server was not contains that. – Tryliom Jul 12 '18 at 07:47

1 Answers1

1

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>
Tryliom
  • 895
  • 1
  • 12
  • 37