Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const httpProxy = require('http-proxy');
- const http = require("http");
- const path = require("path");
- const app = express();
- const bodyParser = require('body-parser');
- var proxyOptions = {
- changeOrigin: true
- };
- httpProxy.prototype.onError = function (err) {
- console.log(err);
- };
- // this should create the node http proxy server on port 3001
- var apiProxy = httpProxy.createProxyServer(proxyOptions).listen(3001);
- // I can see the following output when deploying my app
- console.log('Forwarding API requests to ' + apiForwardingUrl);
- // all incoming / requests on node server should be forwarded to Angular single page app's index.html
- app.get('/', function(req, res) {
- res.sendFile(__dirname + '/index.html');
- });
- // providing static files for Angular app
- app.use("/static", express.static(path.join(__dirname, "static")));
- // all incoming requests to /jira/* should be forwared and responded by node http proxy server
- app.all("/jira/*", function(req, res) {
- apiProxy.web(req, res, {target: 'www.example.com'});
- });
- // make sure POST requests to node http proxy server are fully supported
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({
- extended: true
- }));
- // Create node server on port 3000
- http.createServer(app).listen(3000);
Add Comment
Please, Sign In to add comment