Node forward path request to another server
This works: here's what you need to put in your node app:
var express = require('express');
var app = module.exports = express();
var proxy = require('http-proxy').createProxyServer({
host: 'http://your_blog.com',
// port: 80
});
app.use('/blog', function(req, res, next) {
proxy.web(req, res, {
target: 'http://your_blog.com'
}, next);
});
app.listen(80, function(){
console.log('Listening!');
});
Then in your wordpress app you need to set the Site URL to http://your_node_app.com/blog
Note: You probably already have an express app with probably a body-parser middleware which causes errors and generally doesn't play well with POST requests in http-proxy
You'll find couple solutions in those threads, namely 1: just put this proxy before body-parser, or 2: use connect-restreamer
Worked and Tested
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
app.use('*', createProxyMiddleware({target: 'https://yourdomain.com', changeOrigin: true}));
app.listen(3000);
Install the following first
npm i -s express
npm i -s http-proxy-middleware