Skip to content

Deploying to production server problem #830

Closed

Description

@ekaayakaa

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,

Activity

  1. gaearon commented on Oct 3, 2016

    @gaearon
    Contributor

    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.

  2. jsk548 commented on Jun 15, 2017

    @jsk548

    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.

  3. locked and limited conversation to collaborators on Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions