0

CSS and Images files are not working in my application getting error "Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled"

I have tried "server.use(express.static(path.join(__dirname, 'public')));" but still not working ...

enter image description here enter image description here

const express = require('express');
//const expressLayouts = require('express-ejs-layouts');
const mongoose = require('mongoose'); mongoose.set('useCreateIndex', true);
const passport = require('passport');
const flash = require('connect-flash');
const session = require('express-session');
const server = express();
const path = require("path");
const bodyParser = require("body-parser");


//Set path for static assets
//server.use(expressLayouts);
server.set('view engine', 'ejs');
//server.set('view options', { layout: false });
server.set('views', path.join(__dirname, 'views'));
server.engine('html', require('ejs').renderFile);
//Set path for static assets
server.use(express.static(path.join(__dirname, 'public')));
// Express body parser
server.use(express.urlencoded({ extended: true }));
KiKu
  • 377
  • 5
  • 22
  • 2
    Relative URLs/hrefs, like `href="css/animate.css"`, are relative to the current page's folder, as seen in the Address. The browser sees that as being `/users/`, so you get `/users/` + `css/animate.css`. – Changing the hrefs to be absolute, anchored to the root of the domain by a leading slash – `href="/css/animate.css"` – will inform the browser to ignore the current folder. – Jonathan Lonowski Sep 24 '19 at 06:14
  • For a thorough summary of the differences, along with some related options: [Absolute vs relative URLs](https://stackoverflow.com/a/21828923) – Jonathan Lonowski Sep 24 '19 at 06:24

0 Answers0