How to implement the WordPress REST API with a React UI in such a way that the API endpoints are hidden behind a proxy URL.
I have tried many options like: 1)
const proxy = require('http-proxy');
const proxyUrl = 'http://localhost/mywebsite/wp-json/wp/v2/';
const app = proxy.createServer({
target: proxyUrl,
});
app.listen(3000);
and 2)
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost/mywebsite/wp-json'
changeOrigin: true,
})
);
};
I am getting errors { "code": "rest_no_route", "message": "No route was found matching the URL and request method.", "data": { "status": 404 } }
instead of API response
Please help me out get the solution for this.