There is a MySQL database and a Tomcat server that I am attempting to make a GET request to, using ReactJS + Node.js Express:
My GET request is:
fetchAPI() {
var data = {
'Content-Type': 'application/json',
'start': 'TEST1234567890'
}
var myInit = {
method: 'GET',
mode: 'cors',
header: data,
};
return function(dispatch) {
dispatch({
type: 'FETCH_API'
});
fetch('http://www.localhost:8080/form/upload/post/', myInit)
.then(result=>result.json())
.then(info=>{
console.log(info);
});
}
}
With my Express set up as:
var express = require('express');
var path = require('path');
var config = require('../webpack.config.js');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var app = express();
var compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {noInfo: true, publicPath: config.output.publicPath}));
app.use(webpackHotMiddleware(compiler));
app.use(express.static('./dist'));
app.use('/', function (req, res) {
res.sendFile(path.resolve('client/index.html'));
});
var port = 3005;
app.listen(port, function(error) {
if (error) throw error;
console.log("Express server listening on port", port);
});
And I am getting the error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3005' is therefore not allowed access. The response had HTTP status code 415. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Everything works and runs fine, but once the GET is called, I get the error above.
What am I missing? Any guidance or insight would be greatly appreciated. Thank you in advance!