henryleacock

Untitled

May 13th, 2021
631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // include dependencies
  2. const express = require('express');
  3. const { createProxyMiddleware } = require('http-proxy-middleware');
  4.  
  5. // proxy middleware options
  6. const options = {
  7.     target: 'https://www.famousfootwear.com', // target host
  8.     changeOrigin: true, // needed for virtual hosted sites
  9.     ws: true, // proxy websockets
  10.     router: {
  11.         // when request.headers.host == 'dev.localhost:3000',
  12.         // override target 'http://www.example.org' to 'http://localhost:8000'
  13.         'dev.localhost:3000': 'http://localhost:8000',
  14.     },
  15.     autoRewrite: true,
  16. };
  17.  
  18. // create the proxy (without context)
  19. const exampleProxy = createProxyMiddleware(options);
  20.  
  21. // mount `exampleProxy` in web server
  22. const app = express();
  23. app.use('*', exampleProxy);
  24. app.listen(3000);
RAW Paste Data