6

I am working on ReactJS application using create-react-app.

The npm start and npm run build application is working fine, The application is running in a port number like 4000 or pushstate-server build in the port 9000, The problem is that I need to run the build application without port number in a public url like http://sample/home/ , when I browse directly the build/index.html it is showing the home page correctly but the routings is not working as like in port,All of the css and assets are showing not found.

Venkatesh Somu
  • 4,710
  • 4
  • 23
  • 22

2 Answers2

2

Change the port to 80.

This is the default value for HTTP requests, so, when you try to access
www.google.com
in fact you are accessing
www.google.com:80

Artur Nista
  • 359
  • 1
  • 4
  • I set the port to 80,but the result is same as above, the home is working fine,the remaining pages are showing 404 Not found – Venkatesh Somu Jan 09 '17 at 13:31
  • You need an http server that handles the requests to your routes, you can't simply open the `index.html`. That's what `pushstate-server` does. If you can't use it in production, move to hash based history. – Fez Vrasta Jan 09 '17 at 13:53
  • @VenkateshSomu that's probably a clue that you have another problem that is unrelated to what port is being used. Your browser will have developer tools with with a javascript console, see if it is outputting any errors. – Gimby Jan 09 '17 at 14:16
  • @Gimby , While using pushstate server or http server it is running fine but I need to run without the server like this,need to host the completed app in public url. – Venkatesh Somu Jan 10 '17 at 02:47
0

You have to serve your app with a webserver instead of Webpack Dev Server, which is a dev tool which is not made for production.

Checkout my answer here for more information: How can I serve a reactjs app through https?

SylvainAr
  • 154
  • 5