拒绝应用样式表,因为它是MIME类型,从 ATOM.io 运行到谷歌浏览器



我是一个新程序员,需要一些帮助。我正在尝试启动一个网站,但我的样式表无法加载。错误如下所示:

拒绝应用"http://localhost:3000/stylesheets/home.css"中的样式,因为其 MIME 类型("text/html"(不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。

我知道还有其他类似的错误报告,但我正在运行 Atom.io 到谷歌浏览器。不确定它是否与我的 IDE 或浏览器有关,但我看到的所有其他解决方案都不适合我。我在后端运行 node.js,这是我的代码:

var express = require('express'),

`app = express(),
bodyParser    = require('body-parser'),
mongoose      = require("mongoose"),
passport = require('passport'),
flash = require('connect-flash'),
methodOverride = require('method-override'),
LocalStrategy = require('passport-local');
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static(__dirname + "/public"));
app.set('view engine', 'ejs');

//index
app.get('/',function(req,res){
  res.render('home')
})
app.listen(3000, function(){
    console.log("Your personal website has started")
}); `

谁能帮我?我的前端代码也如下所示:

<html lang = 'en'>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"></link>
  <link href ='/stylesheets/home.css' rel ='stylesheet' type = 'text/css'></link>
</head>

谢谢!杰克

在服务器文件中使用以下代码:

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

在 home.ejs 文件中使用此代码

<link rel="stylesheet" type="text/css" href="/css/app.css" />

最新更新