node.js 引入html沒有css樣式,錯誤Refused to apply style from XXX.css

出現:Refused to apply style from 'XXX.css'  because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

 

我的錯誤,由於html打開正常,所以肯定是 node.js 代碼問題,

這裏是因爲node環境下使用express框架的靜態資源訪問,需要設置靜態文件目錄

代碼如下:

const express = require('express');
const app = express();

var path = require('path');

//加載靜態資源,CSS資源在這個static文件夾下即可
app.use(express.static(path.join(__dirname, './static')));

// 處理根目錄的get請求
app.get('/login',function(req,res){
    res.sendfile('./static/login.html') ;
    console.log('ok');
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章