Issues with loading CSS and JS resources in vue.js running on Kubernetes, encountering a 404 error

We are facing an issue with getting our vue.js application to work on Kubernetes (running in a container using nginx). We are using ingress to route to the site, and below is our configuration:

Dockerfile:

# build stage
FROM public.ecr.aws/docker/library/node:19 as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run build


FROM public.ecr.aws/nginx/nginx:1.24 as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/conf.d/default.conf

nginx:

server {
    listen       80;
    server_name  _;
    access_log  /var/log/nginx/vue-access.log;
    error_log  /var/log/nginx/ve-error.log;
    
    location / {
      root   /app;
      index  index.html;
      try_files $uri $uri/ /index.html;
    }
}

ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: -ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
    - http:
        paths:
          - backend:
                service:
                    name: vue-portal-service
                    port:
                      number: 80            
            path: /
            pathType: ImplementationSpecific

When I access the page, the index.html loads, but the CSS and JS files are not being loaded and return a 404 error. It's strange because everything works fine when I run the Docker image on my localhost.

Any suggestions on what might be causing this issue?

Answer №1

After some investigation, I was able to identify the root cause. Instead of specifying the root path in the Ingress configuration as "/", I mistakenly used "/*".

  - backend:
        service:
            name: vue-portal-service
            port:
              number: 80            
    path: /*
    pathType: ImplementationSpecific

Once I corrected this error, everything started to function as expected.

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

Having trouble initiating NPM in a terminal

I keep encountering an issue whenever I try to start NPM using a command in the terminal. Here is the error message that appears: npm ERR! npm ERR! Did you mean one of these? npm ERR! npm star # Mark your favorite packages npm ERR! npm stars # Vi ...

Can arrays be passed as function parameters in CrossRider without the need to convert them into objects first?

Our team is currently utilizing CrossRider to develop an extension specifically for Internet Explorer. We have a crucial object that is downloaded from , but we are facing an issue where arrays within this object are getting converted into objects with int ...

What is the best way to update or reload an embedded application/pdf?

I have implemented an embed code using application/pdf in order to display a pdf document on the website. To dynamically change the src attribute of the embed when a link is clicked, I utilized javascript. I confirmed this action by displaying alerts to e ...

The window.focus() function does not seem to be functioning as expected when using

I have been trying to use this code snippet to bring the window into focus. It seems to be working smoothly on Internet Explorer, but unfortunately it is not behaving as expected in Firefox. Any tips or recommendations would be greatly welcomed. ((Javas ...

Utilizing query parameters in Next.js

I've been working on a unique Next.js application that incorporates both infinite scroll and a search input feature. The infinite scroll functionality loads 6 additional items whenever the user reaches the bottom of the page. On the other hand, the s ...

Ensuring the canvas fits perfectly within its parent div

I am attempting to adjust my canvas to fit inside a div. // Make the Canvas Responsive window.onload = function(){ wih = window.innerHeight; wiw = window.innerWidth; } window.onresize = function(){ wih = window.innerHeight; wiw = window.innerWidth; } // ...

Execute asynchronous calls within each iteration and proceed to the next iteration in Node.js

I am currently faced with a dilemma at work and I need advice on the most effective approach to handle it. Below is an example of my code: for(var i =0 ;i < collection.length; i++){ asynCall( collection[i],function(){....})//doing a asynchronous cal ...

Creating a Bottom-Up Menu in React Native: A Step-By-Step Guide

Need help figuring out how to create a menu that pops up from the bottom when a button is clicked. Any advice on where to start? If you have any guidance or insights, they would be highly appreciated. ...

Looking for a way to connect a background image in Vue CLI?

When running the code below, I encounter an issue. The code runs properly but the images are not displaying and instead showing the URL as unknown. How can I fix this problem? The images definitely exist. <template> <div class="slider">< ...

Leveraging React's UseEffect() to retrieve information from GraphQL

I am currently attempting to retrieve data from graphQL. I understand that by placing a function inside the react UseEffect(), I can trigger the function once the data is updated and structured. However, while working on a chatroom feature, I am facing an ...

Activate the Masterpage menu to emphasize its current state

I am currently utilizing the AdminLTE template on my website. One issue I have encountered is with the menu and its child menus. When redirecting to different pages using image buttons, the menu collapses back to its original state. While navigating throu ...

Variations of a particular software package are necessary

My current project requires Expo, React, and React-Native as dependencies. The configuration in the package.jason file looks like this: "main": "node_modules/expo/AppEntry.js", "private": true, "dependencies": { "expo": "^28.0.0", "expo-three": "^ ...

Using AngularJS and ServiceStack webservice, perform the "get('url')" operation

I'm completely new to AngularJS and I'm attempting to retrieve some JSON items from a webservice I quickly set up using ServiceStack. When I enter the URL in the browser, I can see the JSON object without any issues. However, for some reason Angu ...

Navigating through Express Js

Here is the API route for retrieving specific information: /Token?l=Spanish&n=NameofTheServer&m0=Email&m1=&m2=&m3=&m4=&m5=&m6=&m7=&m8=&m9=&m10=&m11=&m12=&m13=&m14=&m15=&m16=&m ...

Tips for utilizing the <base> element in HTML5 for selective anchor tags

I only have one base tag in the head section of my HTML document, and there are two anchor tags with different URLs as shown below: <!DOCTYPE html> <html lang="en"> <head> <base href="https://www.youtube.com"/> </head> &l ...

The Vue v-model-bound HTML element is unable to update the Vue instance when a different JavaScript entity binds to it and modifies the data

In my project, I have implemented Vue.js for two-way data binding on a remote control alarm clock. The main code can be found here. You can access the running instance of the server here. While most of the page uses Vue and JavaScript for rendering, I de ...

Suggestions on how to refactor redundant code in various peer AngularJS controllers for handling $intervals

In my compact single-page application, I have implemented multiple tabs to display operational status information for different applications. Each tab is associated with a controller that creates $interval objects to make AJAX calls to fetch status data fr ...

Issue with using puppeteer for testing applications

Having an issue as a beginner in JavaScript, I'm struggling to solve this error. I am fetching data from a website using puppeteer and trying to verify if it's the correct one: const puppeteer = require('puppeteer'); (async () => { ...

An issue with JSPDF arises when used on mobile devices

Currently, I am working on a project to create a responsive web application, which involves utilizing JSPDF for generating PDF reports directly from HTML. For a demonstration of the functionality, you can check out this Demo. Unfortunately, when trying t ...

Leverage the power of integrating Power BI with Javascript to easily retrieve an

I have embarked on a mission to integrate PowerBI into my web application. Below is the code snippet that I have implemented: window.config = { instance: 'https://login.microsoftonline.com/', tenant: 'common', //COMMON OR YOU ...