P
P
PlasterTom2018-07-15 09:06:46
React
PlasterTom, 2018-07-15 09:06:46

How to setup webpack-dev-server proxy?

Good afternoon. The server is on port 3001, the client is on 8080.
How do I set up a proxy for api access? I use axios, the request itself looks like this:

componentDidMount() {
        axios.get('/api/clients')
            .then(function (res) {
                console.log(res);
            })
            .catch(function (err) {
                console.log(err);
            });
   }

I tried to prescribe a line in package.json "proxy": "http://localhost:3001/", I
tried to configure devServer in webpack.config in different ways. One of:
devServer: {
        proxy: [{
            path: '/api/',
            target: 'http://localhost:3001'
        }],
        historyApiFallback: true
    },

None of this worked.
Console errors are different. 504 Gateway Timeout, 404 Failed to load resource: the server responded with a status of 404 (Not Found)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-07-15
@PlasterTom

historyApiFallback: true,
proxy: {
    '/api': {
        target: 'http://localhost:3001,
    },
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question