single-spa-portal-example icon indicating copy to clipboard operation
single-spa-portal-example copied to clipboard

Proxy configuration for production environment.

Open turenc opened this issue 6 years ago • 1 comments

Hi,

Firstly, realy thanks for this amazing work! It's runing smoothly in the development environment.

There is a only dev environment server proxy and a comment for production purposes in "Webpack.config.js". https://github.com/me-12/single-spa-portal-example/blob/master/portal/webpack.config.js // Proxy config for development purposes. In production, you would configure you webserver to do something similar. proxy: { "/app1": { target: "http://localhost:9001", pathRewrite: {"^/app1" : ""} },.....................................................

Can you give an idea about how can i configure web server to do something similar?

Or is there another way?

Thanks, Türenç.

turenc avatar Feb 09 '19 07:02 turenc

This is my try by using node.js with express and http-proxy-middleware dependencies

------ code below ----------

const path = require('path'); const express = require('express'); const proxy = require('http-proxy-middleware'); const app = express();

app.use(express.static(path.join(__dirname, 'release')));

app.use('/app1', proxy({ target: 'http://localhost:9001', changeOrigin: true, pathRewrite: { '^/app1': '/', }}));

app.use('/app2', proxy({ target: 'http://localhost:9002', changeOrigin: true, pathRewrite: { '^/app2': '/', }}));

app.use('/app3', proxy({ target: 'http://localhost:9003', changeOrigin: true, pathRewrite: { '^/app3': '/', }}));

app.use('/app4', proxy({ target: 'http://localhost:9004', changeOrigin: true, pathRewrite: { '^/app4': '/', }}));

app.use('/app5', proxy({ target: 'http://localhost:9005', changeOrigin: true, pathRewrite: { '^/app5': '/', }}));

app.listen(9000);

yzrzya1 avatar Feb 11 '19 19:02 yzrzya1