UI Architect, Full Stack Web Developer – San Francisco Bay Area (Walnut Creek), CA
UI Architect, Full Stack Web Developer – San Francisco Bay Area (Walnut Creek), CA

How to fix a broken proxy after ejecting from a Create React App

It’s fairly simple, and very well documented, how to setup an express server with a CRA (Create React App) application. Simply add a line to the CRA’s package.json file:

"proxy": "http://localhost:3001",

But what happens when you eject from CRA? Once you do that, the webpack configs are entirely up to you. Your one-line proxy in package.json will not work anymore.

Instead, you’ll need to add a couple lines to your webpack.config.js file. This worked for me:

 devServer: {
        proxy: [
            {
                context: ['/api'],
                target: 'http://localhost:3001',
            },
        ],
    },

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.