Routes are no longer being qualified by Express once a subdomain is incorporated

We had developed a compact app that was working flawlessly, but then we were tasked with transforming it into something accessible for others in our organization to utilize... and that led to everything breaking down. Our initial setup included a simple express server with a few API routes along with a React application being served.
Originally, we accessed our app using a URL pattern similar to:

Our express server was listening to routes like:

// server.js:

import "./env";
import app from "app";
import { logger } from "@company/shared-code";

let fs = require("fs");
let https = require("https");

let privateKey = fs.readFileSync(`${process.env.CERT_HOME}/server.key`, "utf8");
let certificate = fs.readFileSync(`${process.env.CERT_HOME}/server.crt`, "utf8");
let credentials = { key: privateKey, cert: certificate };

let httpsServer = https.createServer(credentials, app);
httpsServer.listen(process.env.PORT || 3000, function () {
    logger.info("Application listening on port " + (process.env.PORT || 3000) + "!");
});

// app.js:

import express from "express";
import health from "./routes/health/health.js";

const app = express();
app.use("/app_name/rest/health", health);

app.use(express.static(path.join(process.cwd(), "build")));
app.get("/app_name/ui*", function(req, res) {
    res.sendFile(path.join(process.cwd(), "build", "index.html"));
});

// health.js:

import express from "express";
import os from "os";
import Promise from "bluebird";

const disk = Promise.promisifyAll(require("diskusage"));
const health = express.Router();

// Health route implementation

export default health;

In order to streamline providing proper certificates to new teams leveraging our app, we acquired a wildcard certificate covering *.technology.company.com/app_name/. This allowed the next team to fork the repository and deploy without acquiring additional certificates... which was beneficial.

We patted ourselves on the back for a successful deployment with the updated configuration. However, upon navigating to , every route seemed to be directed to get("/app_name/ui*")... despite numerous debugging attempts, I struggled to comprehend why my "rest" routes were not functioning as expected or reproduce this issue locally.

At present, when requesting , the response received is index.html and the health route is never triggered.

Has anyone encountered a similar issue?

UPDATE: provided supplementary details regarding the implementation

Answer №1

After encountering an issue where the create-react-app service worker was caching resources in a way that prevented Express from being called, it was found that updating the service worker solved the problem.

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

Transform an array of object's designated key values into a string that is separated by commas

Is there a way to convert specific key values of an object into a comma-separated string? I have been able to do this with arrays, but my current challenge is that my data is an array of objects. I want to convert each 'id' value into an array of ...

How can I retrieve and showcase the size of each file, including images, CSS, and JS, present on a website?

Currently, my goal is to create a dashboard capable of retrieving the file size for all resources (images, javascript, css, etc.) loaded on a webpage. I aim to then further filter these resources by file type and file size in order to identify which ones c ...

Turn off the whole DIV container and its contents once the button is clicked

Here's an example of the HTML markup: <div id="picing-selection" class="disableMe"> <a class="upgradeSub" value="@ViewBag.Id"> Upgrade <i class="fa fa-money"></i> </a> </div> The onclick event is d ...

Modifying webpage code

I am looking to develop a system where I can edit various elements such as the navbar, paragraphs, and images directly from a web page. I understand that this can be achieved with JavaScript, but I am facing the issue of my customizations reverting to defa ...

socket.io delivers information to the customer depending on the identification provided by the client

Imagine a scenario where calling a REST endpoint triggers a server-side process that runs for an extended period: http://host/api/program/start The goal is to relay updates and output from this process on the server side to a client application. One app ...

Is there a way to invoke a function in an iframe from its parent?

How can I call a function that is in an iframe from the parent document? If the function were in the parent, I could simply use parent.func(); but since it's within the iframe, how can I still call it successfully? JavaScript keeps saying it can' ...

Looping through and printing JSON strings

Currently, I am dealing with a JSON string of this specific format: {"prey":["{\"distance\": 8.686924173343307, \"signal\": \"-59\", \"frequency\": 2447, \"mac\": \"00:00:00:00:00:00\", \"ip ...

What is the best way to save a webpage when a user clicks a button before leaving the page with Javascript

I've exhausted all my options in trying to find a way to trigger a button that saves the page upon exit, but it never seems to work. I need the event to occur even if the button is not visible at the time of the page exit. The new security protocols o ...

jQuery click event not working post Ajax request returned a 403 error

I am facing an issue with my ajax request where I receive a 403 error message. Strangely, when this error occurs, the click() function associated with the ajax call stops working. There is no manipulation of HTML elements before or after the ajax call, and ...

Obtain the HTML source code for a webpage that has been scrolled down using Python web scraping with Selenium

Even after executing a script to scroll down, I am only able to retrieve the initial html code containing 11 hotels. How can I access the entire data source code by scrolling down to scrape all the available hotels? If the driver.execute_script is suppose ...

Having trouble generating an array for checkboxes using jQuery, AJAX, and PHP

I'm almost there, but there's something missing. I'm attempting to send variables from multiple checkboxes to a PHP page using jQuery. This is my code: <div id="students"> <div class="field"> <label> ...

Parsing the CSV file contents according to the specified columns

Currently, I'm involved in a project using AngularJS where I need to extract data from a CSV file column by column using JavaScript. So far, I've successfully retrieved the CSV data and displayed it in the console. While I've managed to sepa ...

Securing your Angular2 application with TypeScript for enhanced safety

Looking to create a web application using Angular2 with TypeScript. After researching authentication in Angular2, it seems I need to include the following components: index component (public) login component (public) my private component (private) Thes ...

What is the best way to position my content next to my sticky sidebar for optimal visibility?

Just starting out with coding and tackling my initial project using reactJs and bootstrap 5. My aim is to create a sticky side navbar that remains fixed on the side while my content displays next to it, even when navigating through different routes. Unfort ...

Implementing RSA_PKCS1_PADDING encryption and decryption in Express.js

I am currently utilizing express js. While encryption and decryption functions perform as expected in node version 14, I have encountered an issue with node version 20 stating that RSA_PKCS1_PADDING is no longer supported for private decryption. It suggest ...

Developing a feature that allows users to switch between different sets of information

I'm currently exploring a new project and attempting to design a toggle that switches between monthly and annual payments based on the user's selection, much like the functionality found here: . At present, I have implemented two sets of price c ...

Steps for creating a node.js and ejs file to deploy on 000webhost

I have developed a simple todo-app using node.js and ejs templating. My goal is to host it using 000webhost, a free web-hosting service. I successfully hosted a react app for free on this platform by running "npm run build", which converted the ...

Struggling with making react-hook-form correctly validate an email address

I've been struggling for a long time to make this validation work correctly, but it seems impossible. I even added some text at the bottom to display an error message related to the email, but it always shows no error, regardless of the situation. Ed ...

I'm facing an issue where I am only able to update the first record in the database using axios and Post

There seems to be a strange issue where only the first record in the database can be updated, even though all records can be retrieved without any problems. Here is the situation: https://i.sstatic.net/bK5aI.png To clarify further: Since names are unique, ...

Using jQuery to send a post request to a PHP script using either JavaScript or PHP

Just a quick question for those with experience. I am working on a page where I have implemented a jQuery AJAX post to another PHP page that contains JavaScript. My concern is, will the JavaScript code also be executed? Another scenario to consider is if ...