Guest User

Untitled

a guest
Nov 21st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. const express = require('express');
  2. const httpProxy = require('http-proxy');
  3. const http = require("http");
  4. const path = require("path");
  5. const app = express();
  6. const bodyParser = require('body-parser');
  7.  
  8. var proxyOptions = {
  9. changeOrigin: true
  10. };
  11.  
  12. httpProxy.prototype.onError = function (err) {
  13. console.log(err);
  14. };
  15.  
  16.  
  17. // this should create the node http proxy server on port 3001
  18. var apiProxy = httpProxy.createProxyServer(proxyOptions).listen(3001);
  19.  
  20. // I can see the following output when deploying my app
  21. console.log('Forwarding API requests to ' + apiForwardingUrl);
  22.  
  23. // all incoming / requests on node server should be forwarded to Angular single page app's index.html
  24. app.get('/', function(req, res) {
  25. res.sendFile(__dirname + '/index.html');
  26. });
  27.  
  28. // providing static files for Angular app
  29. app.use("/static", express.static(path.join(__dirname, "static")));
  30.  
  31. // all incoming requests to /jira/* should be forwared and responded by node http proxy server
  32. app.all("/jira/*", function(req, res) {
  33. apiProxy.web(req, res, {target: 'www.example.com'});
  34. });
  35.  
  36. // make sure POST requests to node http proxy server are fully supported
  37. app.use(bodyParser.json());
  38. app.use(bodyParser.urlencoded({
  39. extended: true
  40. }));
  41.  
  42. // Create node server on port 3000
  43. http.createServer(app).listen(3000);
Add Comment
Please, Sign In to add comment