mirror of
https://github.com/Mastermindzh/react-starter-kit.git
synced 2025-04-19 05:23:50 +02:00
Added an example of an authentication protected page (tenders) Added an example with the built in proxy (to combat CORS) (tendersguru)
29 lines
699 B
JavaScript
29 lines
699 B
JavaScript
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
|
|
/**
|
|
* Create a simple proxy that automatically removes the prefix endpoint
|
|
* @param {*} app app to configure proxy on
|
|
* @param {*} endpoint endpoint you want to use for the proxy
|
|
* @param {*} target proxy target
|
|
*/
|
|
const createSimpleProxy = (app, endpoint, target) => {
|
|
app.use(
|
|
endpoint,
|
|
createProxyMiddleware({
|
|
target,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
[`^${endpoint}`]: "",
|
|
},
|
|
}),
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Actual proxy configuration
|
|
* @param {*} app app to configure proxy on
|
|
*/
|
|
module.exports = function (app) {
|
|
createSimpleProxy(app, "/tendersguru", "https://tenders.guru");
|
|
};
|