StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

Problem accessing React App Nginx proxy #31

Open fabrico81 opened 6 years ago

fabrico81 commented 6 years ago

Hi, I wrote the application like you outline on the course, I want to make it reachable as application deployed on a Web Nginx server, the application have a link at Reat App. To do this I configured an reverse proxy inside Nginx. My problem is the when I call the Node/React app by the link I only see a white page, all works perfectly in the Browser if I call the Node/React app directly. See below:

package.json (server)

{ "name": "server", "version": "1.0.0", "description": "", "main": "index.js", "engines": { "node": "9.8.0", "npm": "6.0.0" }, "scripts": { "start": "node index.js", "server": "nodemon index.js", "client": "npm run start --prefix client", "dev": "concurrently \"npm run start\" \"npm run client\"" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.16.3", "mongoose": "^5.1.4", "nodemon": "^1.17.5" } }

index.js (server)

`const express = require("express"); const app = express(); const keys = require('./config/Keys'); const mongoose = require("mongoose"); require('./models/User'); require('./models/Profile'); mongoose.connect(keys.mongoURI); const User = mongoose.model('users');

app.use(express.static('client/build')); const path = require('path'); app.get('*', (req, res) => { res.sendFile(path.resolve(__dirname,'client', 'build', 'index.html')); }); `

package.json (client) { "name": "client", "version": "0.1.0", "private": true, "homepage": ".", "proxy": { "/api/*": { "target": "http://localhost:5000" } }, "dependencies": { "react": "^16.4.0", "react-dom": "^16.4.0", "react-redux": "^5.0.7", "react-router-dom": "^4.3.1", "react-scripts": "1.1.4", "redux": "^4.0.0" }, "scripts": { "start": "set HTTPS=true&&react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }

index.js (client)

`import materializeCSS from 'materialize-css/dist/css/materialize.min.css'; import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import { createStore, applyMiddleware } from 'redux'; import reduxThunk from 'redux-thunk';

import App from './components/App'; const store = createStore(() => [], {}, applyMiddleware(reduxThunk));

ReactDOM.render(

, document.querySelector('#root')); ` > Nginix reverse proxy `location /react { proxy_pass http://10.30.1.185:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }` ![screenshot from 2018-06-08 15-04-59](https://user-images.githubusercontent.com/26551169/41176208-93afed6a-6b2d-11e8-874a-c074f9459139.png) ![screenshot from 2018-06-08 15-05-16](https://user-images.githubusercontent.com/26551169/41176221-a165766e-6b2d-11e8-8a8e-f5d71763f54d.png) In the Browswer console I get the following warning: > Loading failed for the Githubissues.
  • Githubissues is a development platform for aggregating issues.