Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying to production server problem #830

Closed
ekaayakaa opened this issue Oct 3, 2016 · 2 comments
Closed

Deploying to production server problem #830

ekaayakaa opened this issue Oct 3, 2016 · 2 comments

Comments

@ekaayakaa
Copy link

ekaayakaa commented Oct 3, 2016

I am facing an issue when in production if the urls are entered directly in the browser address bar it returns a 404 error. This is working properly in development. I was using a simple express server for production.

var express = require('express'),
  app = express(),
  http = require('http'),
  httpServer = http.Server(app);

app.use(express.static(__dirname + '/build'));

app.get('/', function(req, res) {
  res.sendfile(__dirname + '/index.html');
});
app.listen(3001);

Then i found out that this is happening as the server is not configured to handle the push state.

Then i decided to use pushstate-server to serve the production build according to create-react-app guidelines. Can i use this server as the live server to handle approximately 40 000 unique visits per day.

Thanks and Br,

@gaearon
Copy link
Contributor

gaearon commented Oct 3, 2016

Then i found out that this is happening as the server is not configured to handle the push state.

Yes, because you only serve index.html for /. If you want to serve it for all routes, use /* instead. Also I recommend using a static server like Nginx instead of Express for static files. This will scale much better.

Then i decided to use pushstate-server to serve the production build according to create-react-app guidelines.

We do not recommend using pushstate-server in production.
The build output specifically says "serve it locally":

You may also serve it locally with a static server:

Please only use pushstate-server for checking that builds work locally, not for production.

@gaearon gaearon closed this as completed Oct 3, 2016
@jsk548
Copy link

jsk548 commented Jun 15, 2017

Hi ,
i am also having same problem. i just want to know where to write that expessjs code in our project folder and in which file.

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants