index.js
const express = require('express');
// $ npm i glob
const globSync = require('glob').sync;
let app = express();
let proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require);
proxies.forEach(route => route(app));
//...
app.listen(PORT);
./proxies/mk.js
const proxyPath = '/api';
// $ npm i http-proxy
const proxy = require('http-proxy').createProxyServer({});
module.exports = app => {
proxy.on('error', (err, req) => console.error(err, req.url));
app.use(proxyPath, (req, res) => {
proxy.web(req, res, { target: 'https://hub.modnakasta.ua/' });
});
};