there mysql database , tomcat server attempting make request to, using reactjs + node.js express:
my 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 express set 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 getting error:
no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:3005' therefore not allowed access. response had http status code 415. if opaque response serves needs, set request's mode 'no-cors' fetch resource cors disabled.
everything works , runs fine, once called, error above.
what missing? guidance or insight appreciated. thank in advance!
Comments
Post a Comment