Skip to content

Instantly share code, notes, and snippets.

@denniswon
Created March 13, 2020 20:14
Show Gist options
  • Save denniswon/35a5cefab06c8dd8da3bbe7c57b72db1 to your computer and use it in GitHub Desktop.
Save denniswon/35a5cefab06c8dd8da3bbe7c57b72db1 to your computer and use it in GitHub Desktop.
index.js
// include dependencies
const express = require('express');
const { createProxyMiddleware } = require('../../dist'); // = require('http-proxy-middleware');
// proxy middleware options
const options = {
target: 'https://staking.harmony.one', // target host
changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets
pathRewrite: {
'^/*': '/*', // rewrite path
},
router: {
// when request.headers.host == 'dev.localhost:3000',
// override target 'http://www.example.org' to 'http://localhost:8000'
'dev.localhost:3000': 'http://localhost:5000'
}
};
// create the proxy (without context)
const exampleProxy = createProxyMiddleware(options);
// mount `exampleProxy` in web server
const app = express();
// Declare static folder to be served. It contains the js, images, css, etc.
app.use(express.static('build'));
app.use('/', exampleProxy);
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment