Created
March 13, 2020 20:14
-
-
Save denniswon/35a5cefab06c8dd8da3bbe7c57b72db1 to your computer and use it in GitHub Desktop.
index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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