0

I have frontend-app, written using React, which use api-server https://koalerplate-xxxxxxx.now.sh".

//package.json

{
     ...
      "dependencies": {
        "bulma": "^0.7.1",
        "react": "^16.4.1",
        "react-dom": "^16.4.1",
        "react-redux": "^5.0.7",
        "react-scripts": "1.1.4",
        "redux": "^4.0.0",
        "redux-saga": "^0.16.0"
      },
      "scripts": {
        "start": "react-scripts start",
      },
      "proxy": "https://koalerplate-xxxxxxx.now.sh"
    }

"npm start", then in browser opening "localhost:3000" and all working correctly. How can I deploy this app ? How I must apply "proxy": "https://koalerplate-xxxxxxx.now.sh" ? I tried use webpack for build, got index.html + bundle.js, and upload this 2 files to static server, but not working.. and in file bundle.js I can't find this proxy "koalerplate-xxxxxxx.now.sh"

2
  • based on your start script, is this app using create-react-app? Commented Jun 27, 2018 at 14:03
  • yes, using create-react-app Commented Jun 27, 2018 at 16:26

2 Answers 2

1

Create-react-app allows you to use environment variables. You can find more info defined here : https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

When you run npm run build it generates static html/css/js files and does not use the package.json any longer so the proxy will not apply. You need to define an environment variable like the documentation shows and when you do a build, it will apply the value of the environment variable to your application.

Sign up to request clarification or add additional context in comments.

Comments

0

You're going to use npm run build to create a static file, and then you can host that using any static file server you want (for example, Node/Express). However, things get more complicated if you're using React-Router.

Here's the link to the complete guide on this subject: Deployment Instructions

It's very thorough and should answer all your questions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.