Timbo
Timbo

Reputation: 487

Deploying React App to Apache Server

I have a finished react app that works well on my localhost with npm start. I created the project with create-react-app and used the npm run build to compile a production website.

I have the whole folder with the index.html on my webspace. (They use an apache html server).

I managed to write an .htaccessfile that loads the html correctly. Now there is only a white screen. It seems like the main.js is not being loaded into the root div.

The only error I get in the console is that the service-worker could not be installed as my request comes not from a secure origin. This should not stop the rendering right?

I am not sure what files would be necessary to show here so please do let me know what you need to see to hopefully fix the problem.

Thank you!

Upvotes: 5

Views: 10177

Answers (2)

Abhishek Singh
Abhishek Singh

Reputation: 1671

After Running npm run build command.

Copy and paste everything in build folder to your server.

Create a “.htaccess” file and add this snippet :

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

The application should work correctly.

Upvotes: 5

sheunglaili
sheunglaili

Reputation: 318

maybe its because you have ProxyPass in your conf file. you need to specific the homepage of your application.

{ "name": "application-name", "version": "1.0.0", "description": "", "homepage": "https://www.yourdomain.com/appliaction-context-path", }

Upvotes: 1

Related Questions