Proxy server is responsible for Apache

I just created a responsive app using the create-react-app and starting the app in port 3000, fine. I would like to access the application with a prefix in my case / node and in port 80, i.e. http: // localhost / node . For this, I configured apache with:

<Location /node> Allow from all ProxyPass http://localhost:3000/ retry=0 ProxyPassReverse http://localhost:3000/ </Location> 

And it works partially, I can access http: // localhost / node , but the page does not load correctly because the route to the package is static, Sort console, I see the http: //localhost/static/js/bundle.js request fail if not found.

bundle.js is not located in index.html, so it should be entered webpack.

I was looking for where to configure webpack to change the configuration to put bundle.js in node / static / js / bundle.js or something like that.

+1
source share
3 answers

I generated the build folder by running

 sudo npm run build 

in the root folder of the application. Then I created the / var / www / html / app folder and copied the index.html file and related files into it. I also had to fix the file paths in index.html.

Then open the response application by clicking on the link http: // localhost / app .

0
source

How not to use apache proxy.

Change "package.json", add

 "homepage": "http://localhost/" , 

Not "homepage": "http://localhost/node"

Result:

 $ head package.json { "name": "reactapp", "private": true, "homepage": "http://localhost/", "devDependencies": { .... 

To run

 npm run build 

Creating a symbolic link

 ln -s create-react-app/build /var/www/html/node 
0
source

I had the same problem that I solved with the publicPath property of publicPath : https://webpack.js.org/guides/public-path/

In my configuration, I associated this property with an environment variable:

  output: { path: path.resolve(process.cwd(), 'build'), publicPath: process.env.PUBLIC_URL || '/', } 

In your case, you run something like PUBLIC_URL=/node npm run build . This will force Webpack to add /node to each URL in index.html .

0
source

All Articles