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>