出现: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');
});

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐