【发布时间】:2021-05-08 18:29:45
【问题描述】:
http://localhost:3000/css/styles.css 给了我:
无法获取 /css/styles.css
.
├── public
├── css
│ ├── styles.css
│─── app.js
│─── signup.html
链接了我的公共静态文件,但是当我运行节点服务器时,css 似乎不适用于我的 html。我附上了在静态与节点端口 3000 上本地运行它的屏幕截图。
希望有人可以帮助我。
我的 app.js
const express = require("express");
const https = require("https");
const path = require("path");
const app = express();
app.use(express.static("public")); //indicates the directory for static items e.g css
app.get("/", function(req,res){
res.sendFile(__dirname + "/signup.html");
});
app.listen(3000, function(){
console.log('server is running on port 3k');
})
我的 html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign up for newsletter</title>
<link href="css/styles.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div class="wrapper fadeInDown">
<div id="formContent">
<div>
<h1>Sign up to get the latest updates!</h1>
</div>
<!-- Tabs Titles -->
<!-- Icon -->
<div class="fadeIn first">
<img src="https://natisaver.github.io/cv/images/mugicon.png" id="icon" alt="User Icon" />
</div>
<!-- Login Form -->
<form>
【问题讨论】:
-
如果你在浏览器中打开开发者工具,控制台会显示什么?
-
localhost/:1 拒绝应用来自 'localhost:3000/css/styles.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。跨度>
-
未捕获的类型错误:无法在 bootstrap.min.js:6 在 bootstrap.min.js:6 localhost/ 的 util.js:10 读取 util.js:68 处未定义的属性“fn”: 1 拒绝应用来自 'localhost:3000/css/styles.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
-
在你的目录树结构中它显示
_css,这可能是问题吗?
标签: javascript html css node.js express