The modification of Javascript content type occurring following URL Rewrite

I'm currently working on setting up a Reverse Proxy with ARR and URL rewrite in order to achieve the following redirection:

The goal is for the final URL displayed to be same as the source URL.

While the redirection works correctly, all my JavaScript files are being transformed into content-type text/html instead of application/javascript when accessed externally. This results in a blank page instead of the expected functionality.

Here is the Rewrite rule I am using:

<rules>
...
  <rule name="ReverseProxyInboundRule2" stopProcessing="true">
    <match url="^test(.*)" />
    <action type="Rewrite" url="http://{HTTP_HOST}:83/{R:1}" />
  </rule>
</rules>
<outboundRules>
  <rule name="ReverseProxyOutboundRule1" preCondition="IsJavascript">
    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" customTags="" pattern="^http(s)?://localhost:83/(.*)" />
    <action type="Rewrite" value="http{R:1}:{HTTP_HOST}/{R:2}" />
  </rule>
  <preConditions>
    <preCondition name="IsJavascript">
      <add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/javascript" />
    </preCondition>
  </preConditions>      
</outboundRules>

Since the destination page relies on AJAX functionality and the javascript files are being corrupted with random html tags, the AJAX functions are failing. How can I go about fixing this issue?

Answer №1

After thorough investigation, it was determined that the problem stemmed from the use of relative paths within the destination application. Upon proxying, critical resources such as JavaScript and CSS files were being incorrectly redirected to a custom 404 error page belonging to the source application. Fortunately, I successfully resolved this issue by making necessary adjustments to the code.

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

What could be causing the error message "CSRF token missing or incorrect" to appear?

I am facing an issue with returning a value from a View function in Django. This particular function is called from a JavaScript code using Ajax, but I'm encountering an error that says 'Forbidden (CSRF token missing or incorrect)'. JavaScr ...

Is there a way to use the same color picker tool for adjusting both the background and text colors simultaneously?

My goal is to create functionality where the user can change the background color by clicking on the background of the div, and change text color by clicking on the text within the div. var box1 = document.querySelectorAll('.color1'); var pic ...

Node.js is powering the serving of HTML along with the execution of command-line operations and callback

I am trying to utilize Node.js to serve a single HTML file and respond to a request on the same port. In addition to serving the HTML page, I also want to run a local command to display the output of that command. However, I am encountering errors and unab ...

Is combining Nuxt 3 with WP REST API, Pinia, and local storage an effective approach for user authentication?

My current project involves utilizing NUXT 3 for the frontend and integrating Wordpress as the backend. The data is transmitted from the backend to the frontend through the REST API. The application functions as a content management system (CMS), with all ...

Exploring the power of Vue3 with Shadow DOM in web components

I've been experimenting with web components using Vue3 and I'm curious about how the Shadow DOM works. I encountered an issue where a third party library was trying to access elements using getElementById() and it was throwing an error because th ...

Sending information from one Angular 2 component to another

As a newcomer to Angular 2, I am still in the process of understanding its functionalities. Currently, I have two components: 1) List Component This component is responsible for displaying all the products in a store and performing various functions. @C ...

Unable to retrieve the second number enclosed in parentheses using regular expressions

Currently, I am diving into the world of regex and encountering a set of strings formatted as "(9/13)". My goal is to retrieve the second number in this format. To achieve this, I experimented with the following regex pattern: /\(.*?[^\d]*(\ ...

Utilizing JSON Data for Dynamically Displaying Database Objects on a Google Map

After carefully reviewing the information provided in the initial responses and working on implementation, I am updating this question. I am currently utilizing the Google Maps API to incorporate a map into my Ruby on Rails website. Within my markets mode ...

A helpful tip for dynamically adjusting the canvas size is to utilize its height and width attributes to resize it whenever it undergoes a change

I am encountering an issue with the canvas element in my code. The canvas is supposed to update whenever its containing div is resized. window.addEventListener('resize',function() { let mapwidth = $('.canvas').attr("width") l ...

Validating emails using React.js and HTML5

In my React component, I have an email input field: <input type="email" autoComplete="email" placeholder="Email" required value={this.state.formDa ...

Issue with Checkboxlist losing selection in Internet Explorer after postback

Technology: ASP.Net 2.0 Within the confines of a webpage, there are multiple checkboxlist controls that correspond to an equal number of buttons. Initially, all the checkboxlist controls remain concealed. When a user clicks on a button, the respective che ...

Angular filter within a nested ng-repeat loop

I've encountered an issue with nested filtering in Angular, where two filters are dependent on each other. What I'm trying to achieve is the following: <div ng-repeat="g in groups | filter:groupFilter"> ... <tr ng-repeat="c in g.co ...

NodeJs is facing a challenge with the global variable for retrieving all routes methods after successful sign in

I have created a blog page with options for signing up and signing in. I used the req.locals.<name> method Using the GET method. Code snippet from server.js app.get('*',(req,res, next) => { res.locals.user = req.user || null; ...

In search of a jQuery parser for HTML strings that can accurately parse <a> links and <img> images

Is there a HTML string jQuery parser available, specifically for parsing <a> links and <img> images? Alternatively, I am looking for code that can extract all links and images from a HTML string, which can potentially be very large. For exampl ...

The technique of binding methods in React

When working with React.js, it's recommended to define your method binding in the constructor for better performance. Here's an example: constructor(props){ this.someFunction = this.someFunction.bind(this); } This approach is more efficient t ...

What steps can I take to rearrange my return statement within an asynchronous function?

Imagine having a function that fetches data from a database. findById(id) { return Model.findById(id) } The goal is to rearrange the output from the user data in this format: { name: "Tom", age: 57 } To something like this: { message: ...

Steps for redirecting to an external URL with response data following an HTTP POST request:

this.http.post<any>('https://api.mysite.com/sources', [..body], [...header]) .subscribe(async res => { const someData = res.data; const url = res.url; window.location.href = url }) After redirecting to the specified UR ...

Button click event is not being triggered by Ajax rendering

I am facing an issue with my Django template that showcases scheduled classes for our training department. Each item in the list has a roster button which, when clicked, should display the class roster in a div. This functionality works perfectly. However, ...

Adjust the code to enhance the functionality of web components in Sharepoint

I recently came across some code online that I'm trying to modify in order to add an expanding button next to a web part on my Sharepoint site. However, the problem is that by default, all web parts are already expanded and require a click to collapse ...

Tips for customizing the appearance of a React-Table header when sorting data

How can I change the header's background color in react-table based on a selected item? For example, if I click on ID, the ID header should change its background color to red. I have tried various methods to update the background color upon selection ...