When navigating to a deeper URL link in html5mode, ExpressJS is displaying an incorrect static path

My goal is to implement html5mode in my web application using Angular's ui router. The client side works as expected, with the main webpage (127.1.1.1:8080) loading perfectly and navigating to (127.1.1.1:8080/admin/dashboard) also functioning smoothly.

Refreshing 127.1.1.1:8080 works fine without any issues.

The problem arises when attempting to refresh the page at 127.1.1.1:8080/admin/dashboard, resulting in:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://127.1.1.1:8080/admin/libs/components-font-awesome/css/font-awesome.min.css".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://127.1.1.1:8080/admin/assets/css/style.css".

It appears that the css style is being retrieved incorrectly. The path is incorrect; it should be . I have already attempted to rewrite the static path in my server.js file, but the issue persists. What am I missing?

server.js

var express = require('express'),
    app = express(),
    mongoose = require('mongoose'),
    bodyParser = require('body-parser'),
    api = require('./app/routes'),
    port = process.env.PORT || 8080; 

app.use('/app', express.static(__dirname + '/public/app'));
app.use('/assets', express.static(__dirname + '/public/assets'));
app.use('/libs', express.static(__dirname + '/public/libs'));

app.post('/api/user', api.post);
app.all('*', function(req, res, next) {
    res.sendFile('/public/index.html', { root: __dirname });
});

app.use(bodyParser.json()); 

app.listen('8080');
console.log('The magic happens on port 8080');

app.config.js

angular
    .module('app')
    .config(config);

config.$inject = ['$urlRouterProvider','$stateProvider','$locationProvider'];

function config($urlRouterProvider,$stateProvider,$locationProvider) {
    $urlRouterProvider.otherwise('/');

    $stateProvider
    .state('home', {
        url:'/',
        templateUrl: 'app/home/home.html',
        controller: 'HomeController',
        controllerAs: 'vm'
    })
    .state('admin', {
        url:'/admin',
        templateUrl: 'app/admin/admin.html',
        controller: 'AdminController',
        resolve: {app: check_logged}
    })
    .state('admin.dashboard', {
        url: '/dashboard',
        template: 'I could sure use a drink right dashboad.'
    })
    .state('admin.product', {
        url: '/product',
        template: 'I could sure use a drink right product.'
    })

    $locationProvider.html5Mode({
        enabled: true
    });
}

index.html

    <head>
    <meta  http-equiv="content-type" content="text/html;" charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="/libs/materialize/dist/css/materialize.min.css"></link>
    <link rel="stylesheet" href="/libs/components-font-awesome/css/font-awesome.min.css"></link>
    <link rel="stylesheet" href="/assets/css/style.css">
    <base href="/">
</head>

Answer №1

To solve the problem, include the type attribute in your CSS code like this -

 <link rel="stylesheet" type="text/css"  href="/libs/materialize/dist/css/materialize.min.css">

The error is linked to the mime-type.

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

Ways to implement a custom scrollbar across an entire webpage:

I am trying to implement the Jquery custom content scroller on my webpage to replace the default scrollbar. However, I am facing difficulties in getting it to work properly. You can view my code on Codepen. Although the plugin works fine with smaller blo ...

LabeFor does not automatically create the display-lable class attribute

When setting up a new MVC project, the default Site.css file typically includes the following styles: /* Styles for editor and display helpers ----------------------------------------------------------*/ .display-label, .editor-label { font-weight: ...

`Is JSON causing strange caching problems?`

When I retrieve data from my PHP, everything seems to be working fine. However, the issue arises when var myData is getting cached and only updates after refreshing the page twice... On Firebug, I can see that the post updates are coming through, but when ...

Executing a Javascript function using ssl

As a newcomer to SSL and Javascript, I hope you'll pardon any lack of knowledge on my part. I've been trying to research my question online, but haven't had much luck finding the answer. Context In simple terms, my website has a subdomain ...

Establish an environment variable in webpack for apache2

Can you access a webpack environment variable outside of the node/js scope? I am working on a project using vueJS and TYPO3, where I need to load JS files from the node server during runtime. Otherwise, I want to load the pre-built JS files from the proje ...

The method for Mongoose instance cannot be found

I have utilized Mongoose to create a custom method for user authentication: UserSchema.methods.authenticate = function(password){ return this.encryptPassword(password) === this.hashed_password; }; When attempting to authenticate a user in my applicatio ...

Creating alternating colored divs can be achieved by applying a styling rule to select every

Struggling with a piece of code where I want to alternate the background color to #F8F8F8 in .itemrow. Check out the code here: http://pastebin.com/mgHYzJAd .itemrow { padding-top:20px; padding-bottom:20px; background-color:#f8f8f8; } Also, ...

Is this example showcasing the use of JavaScript closures?

I have a JavaScript query that may be geared towards beginners: var countries = [ "Bangladesh", "Germany", "Pakistan"]; function checkExistence(arr, input) { for (var i = 0; i < arr.length; i++) { if (arr[i] != input) { a ...

The functionality of Ajax is limited when it comes to handling multiple div elements at the same

Seemingly silly question ahead, but I've been grappling with it for days to no avail. If anyone can help me solve this, please state your price and provide your PayPal details – the money is yours :). What I'm trying to achieve is to add a "Add ...

Attempting to decipher the @media queries CSS code responsible for the slider on this particular website

I'm having trouble with the cover not fully expanding when the browser size is less than 750. I am new to using bootstrap. For reference, I am looking at this website: CSS .slide-wrapper { position: relative; } /* Not using now .carousel-caption ...

Crockford Section Seven - Crafting the Perfect Matcher

Upon testing the code from a book on page 72 in both FF and NodeJS, it was discovered that y.lastIndex equaled 0 and x === y evaluated to false. Why is there a discrepancy between the book's information and the actual behavior of the code? function ...

Encountering issues with launching the React App, it displays an error instead

While trying to set up a React app, I followed all the steps to create the necessary files and folders in the environment. However, when running the npm start command, an error occurred: C:\Users\name\myfirstreact>npm start $ react-script ...

How can we design a CSS layout where elements are positioned fixed on the left but dynamically adjust to prevent overlap?

I'm currently working on creating a layout that features a list of labels positioned at fixed percentage intervals. However, I am facing difficulty as I want these labels to move down onto separate lines if the page width is reduced in order to preven ...

Explore the world of interior CSS border styles

Trying to achieve a unique border effect like the one shown in the image. Experimented with different styles such as inset, outset, ridge, and groove, but unable to get the desired outcome. Is there a way to create a border that bends inwards towards the m ...

Guide on setting up a connection to Hyperledger Fabric Gateway Service (recently introduced in HF 2.4) while ensuring TLS is enabled

My Hyperledger Fabric network setup is functioning well, except when I attempt to utilize the new Fabric-Gateway SDK (). I recently upgraded my network from version 2.3.1 to 2.4.1 and wanted to experiment with the new SDK, but I am encountering connection ...

Generate a Monaco Editor within a Vue.js component

Currently, I am integrating Monaco Editor with Vue.js and facing some confusion regarding how Monaco is being instantiated within the Vue component: 1) In my data() method, I have defined an editorEx object to be used for this purpose, like so: data() { ...

NodeJs and the Power of Event Emitters

As a newcomer to Nodejs, I am diving into learning from various code snippets that I have come across on the internet. My current curiosity lies within a basic question regarding a chat application code snippet. Let's take a look at the code snippet ...

Error message in Leaflet JS: Unable to access property 'addLayer' because it is undefined when trying to display drawnItems on the Map

My attempt to showcase a Leaflet Map with polygon-shaped surfaces encountered an issue. Sometimes, I face the error "cannot read property 'addLayer' of undefined," but when the page is refreshed, the map renders correctly. I am unsure where I wen ...

What are some methods to identify the cause of a click not registering?

While browsing through the page, I noticed a link that looks like this: <a href="/go/some/where.htm">...</a> This link is situated within a google.maps.InfoWindow box that appears when a user hovers over a map pin. Oddly enough, when a user t ...

Showing an array in angular.js

When sending data to a PHP file, the file processes it and performs an SQL search, returning a list of names in a for each statement. For example: Ryan, Jack, Billy, Sarah. However, when echoing the response in Angular, all the names are joined together l ...