I'm primarily a java developer and have minimal node.js experience. I've developed a java spring app, and decided I wanted a minimal front end for it, which I've done in React, created with the Create React App. I had problems deploying and running it in AWS with certain port restrictions, so it was recommended to me to use the frontend-maven-plugin to package it all together into a jar and run it from there. I have done this successfully, at least locally.
However, now I want to go back into development mode and add more features, it seems that something is blocking the response from the server from getting back to the front end. When I say development mode, I mean I've gone back to use 'npm start', with the local react client running thru port 3000, and an entry in package.json for the proxy to point to my local running api. I have verified that the request from the React page is getting to the server, but then the response never gets back to the client. I've looked at the network traffic in Chrome developer and all it says is "Failed to load response data".
When I make a request to the same api endpoint, in a browser for example, the response is returned fine. The response is a simple json.
I'm using fetch in the React components to call the backend api. Example below.
I'm assuming that node or NPM installed something when I ran it via maven and frontend-maven-plugin that is affecting this. NPM is a giant black box to me, so I'm not sure how to further diagnose this or look for what is blocking the response to the react page.
project structure looks like this:
/root-app-repo-name
/app - the React app; unfortunately named when created with Create React App
/build
/node
/node_modules
/node_modules
/public
/src
/src - java source
/target
maven build output jar is here
pom.mxml
Why are there 2 node_modules folders?
Sample React component calling API with fetch:
import React, { Component } from 'react';
import { Button, Container, Table } from 'reactstrap';
class Account extends Component {
constructor(props) {
super(props);
this.state = {account: {}, isLoading: true};
}
componentDidMount() {
this.setState({isLoading: true});
fetch(process.env.API_URL+'/api/account')
.then(response => response.json())
.then(data => this.setState({account: data, isLoading: false}));
}
render() {
const {account, isLoading} = this.state;
if (isLoading) {
return <p>Loading...</p>;
}
return (
<div>
<Container fluid>
Account Num : {account.accountNum}
</Container>
</div>
);
}
}
export default Account;