I have this code using CRA --template typescript
in setupProxy.js
file
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/user/try',
createProxyMiddleware({
target: 'http://localhost:8002',
changeOrigin: true,
})
);
};
but the problem is that setupProxy.js
file is completely ignored causing my request to fail.
I know I can use the "proxy": "http://localhost:8002"
in package.json
but it will not accept multiple proxies.
To further test, I also created a new CRA
but without typescript and suddenly it's working with the same code above.
Is there a way to make setupProxy.js
work in CRA typescript?
New App From Scratch If you're building a new app and using create-react-app , the docs are great: You can start a new TypeScript app using templates. To use our provided TypeScript template, append --template typescript to the creation command.
Should be able to just add this to your tsconfig.json. Hope it works for you.
"exclude": ["src/setupProxy.js"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With