Yes.
Yes.
"proxy" and "setupProxy"
make a src/setupProxy.js with Flow annotations (the ": *") like,
// @flow
const proxy = require('http-proxy-middleware');
module.exports = function(app: *) {
app.use(proxy('/api', { target: 'http://localhost:3001/' }));
};
yarn startThe usual dev server startup
$ yarn start
yarn run v1.7.0
$ react-scripts start
Unexpected token :
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
This is the expected behavior. This file runs in the Node environment and as such, only supports its syntax.
df98c0c5611174266a7161fa716a142791eea13b
I stumbled upon this issue #5185 because I was experiencing the exact same "Actual Behavior". What fixed things for me was changing my setupProxy.js file from this:
# setupProxy.js
import proxy from 'http-proxy-middleware';
export default function(app) {
app.use(proxy('/api', { target: 'http://localhost:5000/' }));
};
to this:
# setupProxy.js
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy('/api', { target: 'http://localhost:5000/' }));
};
I'm commenting incase it saves someone else time in the future.
@RodneyU215 that proxy seems pretty simple, does the normal proxy string option not work for your use case?
Don't mind me if it was a reduced case.
Hi @Timer! Yes the normal proxy string does work for this use case. I was merely highlighting the incompatibility with es2015 module syntax.