Utilize Node.js to proxy Angular requests to a service hosted on Azurewebsites

I am trying to set up a proxy post request in my Node.js server and receive a response from the target of this request. Below is an excerpt from my server.js file code where I have implemented the proxy, but I am facing a issue with not receiving any response:

 var httpProxy = require('http-proxy');
 app.use(bodyParser.urlencoded({ extended: true }));

 var apiProxy = httpProxy.createProxyServer({
     secure: true,
     changeOrigin: true
 });

app.post('/v1/*', function(req, res) {
    apiProxy.web(req, res, { target: 
    'http://somesite.azurewebsites.net'});
    });
});

I am currently working on localhost:3000 and have successfully tested the proxy with another local server on localhost:8888, which worked perfectly.

If I remove changeOrigin: true, I receive a 404 response from the Azure website saying "Page does not exist". However, the service is functional (as confirmed by Postman).

I am struggling to identify the root cause of this issue. Any insights or resources related to node and proxy servers would be greatly appreciated. Thank you!

Answer №1

I don't have much experience with http-proxy, but I think using request could be a simpler option for proxying requests. Here's an example of how you could achieve this:

var request = require('request');
var express = require('express');
var app = express();

app.use(bodyParser.urlencoded({ extended: true }));

app.post('/v1/*', function(req, res) {
    var newurl = 'http://somesite.azurewebsites.net';
    request(newurl).pipe(res);
});

app.listen(3000);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with redirect using Node.js promise

I’ve created a settings page where users can add and remove filters. To handle the deletion process, I’ve implemented this jQuery function: $('#delete-filter').click(function (e) { var filtername = $('#filter-list').val(); ...

What is the reason behind Google Closure Compiler appending a variable to the global namespace when the original namespace was blank?

My long script is neatly enclosed within a (function() {/.../})() to prevent any name pollution. It has been typed with complete accuracy and zero warnings. I recently discovered that Google Closure compiler initially redefines i and j in the global names ...

Update the content on the webpage to display the SQL data generated by selecting options from various dropdown

My database table is structured like this: Name │ Favorite Color │ Age │ Pet ────────┼────────────────┼───────┼─────── Rupert │ Green │ 21 │ ...

What sets express-session apart from cookie-session?

I'm just starting out with Express. Since Express 4.x no longer has bundled middlewares, any middleware I want to use must be required. Reading the README for both express-session and cookie-session on GitHub, I'm finding it difficult to understa ...

Is there a way to prevent a .load() function from executing if it has

On my webpage, I have implemented multiple buttons that each load a different partial "view" using the jQuery .load() method. While this functionality works well, I observed that repeatedly clicking on one specific button results in the partial view being ...

What is the best way to stream an app's data directly to a browser in real time?

My node application is currently able to read a stream from a Kafka producer and display it in real time using console.log. However, I would like to update my web application with the same real-time functionality. How can I achieve this? I typically start ...

Creating a function that uses setInterval to continuously update the input with a specific value

I am looking to use the setInterval function to continuously update the value of #test1. Additionally, I want the value of #test1 to be cleared and reset to 1 second after the user clicks a button. Example output can be found here: http://jsfiddle.net/eK ...

How can I render just one event instead of all events when using the eventRender callback function?

I am currently working on adding an event to my calendar using a JSON format with specific attributes like id and start time. Here is what I have tried so far: $('#calendar').fullCalendar('renderEvent', my_event); $('#calendar& ...

What impact does the //g flag in Regex JavaScript have on the program's state?

I recently had a question that was answered, but I'm still trying to grasp why the regex behaves in a certain way. According to w3schools, it explains: g: Perform a global match (find all matches rather than stopping after the first match) Okay, ...

Tips on converting Django model into desired format for Bootstrap-tables plugin integration

I want to integrate the bootstrap-table plugin with server-side functionality using Django Rest Framework to populate the data on the table. However, I keep getting the message "No matching records found". After some investigation, I discovered that a spec ...

How to Handle Empty Input Data in JQuery Serialization

Having an issue with a form that triggers a modal window containing another form when a button is clicked. The second form includes an input field and send/cancel buttons. The goal is to serialize the data from the modal form and send it to a server using ...

Troubles encountered when running the "npm run dev" command on a new installation of Laravel 5.4

After struggling for 5 hours, I am still unable to resolve this issue. When attempting to run "npm run dev" on a fresh Laravel installation, the following error is displayed: > @ dev /var/www/html/capsule > cross-env NODE_ENV=development node_module ...

Which command should I opt for - webpack or webpack-cli?

After researching the webpack package and the webpack-cli package, I have realized that both need to be installed for webpack commands to work properly. In webpack 3, there was only one package that included the command line functionality. However, in webp ...

Is it advisable to include gulp modules in the devDependencies section when deploying on Openshift platform?

My project has a build process that involves compiling Sass, minifying JavaScript, and processing templates in the deployment hook of OpenShift. I'm debating whether to place these Gulp modules in devDependencies as is commonly done, or if they actua ...

Dealing with timeout errors when using Puppeteer's page.waitForNavigation()

When using puppeteer, I initiate a page by entering a value and it displays the resulting output. await page.click('button[class="button form-button rs-gcbalance-btn"]') await page.waitForSelector('div[class="small-4 large-4 rs-gcbalance-r ...

Troubleshooting issue: AngularJS NVD3 line chart directive does not refresh after data update (not updating in real time)

I am currently facing an issue with the nvd3-line-chart directive in my AngularJS application. The chart does not redraw when I change the underlying model... As a newcomer to AngularJS, there may be something obvious that experienced programmers will not ...

Creating a file solely for route definitions and then employing them within index.js

My index.js file contains the following routes: import { createRouter, createWebHistory } from '@ionic/vue-router'; import { RouteRecordRaw } from 'vue-router'; const routes = [{ path: '', redirect ...

Generate a fresh object if the values within the TypeScript object are identical

How can I filter an object to return a new object containing elements with the same values? For example: allValues = {"id1": 3, "id2": 4, "id3": 3} The desired output is: filteredValues = {"id1": 3, "id3": 3} This is because the keys "id1" and "id3" hav ...

ReactJS components enhanced with bootstrap-table JS extension

I recently downloaded the bootstrap-table package from NPM (npmjs.com) for my ReactJS application. It provides great features for setting up tables and datagrids. However, there are additional js and css files needed to enhance its functionality. These inc ...

Pause the ajax response using jQuery

I encountered a simple issue that is causing me trouble. It seems that when I send an ajax request, there isn't enough time to assign the value to the combonews variable: jQuery.ajax({ type: "POST", url: "People.aspx/LoadCombo ...