[英]My first app doesn't serve css even if I set express.static() and have a correct path
As the title says I'm trying to build my first node app and I'm encountering a problem. 正如标题所说,我正在尝试构建我的第一个节点应用程序而我遇到了问题。
Yesterday everthing worked fine. 昨天一切顺利。 Now when I opened up my PC I get "Resource interpreted as Stylesheet but transferred with MIME type text/html: " http://localhost:3000/css.css "." 现在,当我打开我的电脑时,我得到“资源解释为样式表,但使用MIME类型text / html传输:” http:// localhost:3000 / css.css “。”
I find it very strange because I didn't edit anything, and it stopped working. 我觉得很奇怪,因为我没有编辑任何东西,它停止了工作。
/*Libraries*/
var express = require("express"),
app = express()
/*Routes*/
var indexRoute = require("./routes/index");
app.use(indexRoute);
/*Modeles*/
/*Configuration*/
app.set("view engine", "ejs");
app.use(express.static('public'));
app.listen(3000, function() {
console.log("==================================");
console.log("===Serverul a pornit cu succes!===")
console.log("==================================");
});
var express = require("express"),
router = express.Router()
router.get("*", function(req, res) {
res.render("index/404");
});
module.exports = router;
<% include ../../partials/header %>
<section id="container-404" class="container-fluid">
<div class="row">
<div class="col-12">
<h1 class="display-1">404</h1>
</div>
</div>
</section>
<% include ../../partials/footer %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/reset.css">
<link rel="stylesheet" href="/fontawesome-all.min.css">
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans:400,800" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="/css.css">
<title>Best DavNic73</title>
</head>
<body>
root { app.js root {app.js
partials > footer.ejs, header.ejs partials> footer.ejs,header.ejs
public > css.css and the other 2 css files public> css.css和其他2个css文件
routes > index.js routes> index.js
views > index > 404.ejs } views> index> 404.ejs}
You currently got the following routing -> 404 -> public
. 您目前有以下路由-> 404 -> public
。 That means that the 404 route catches all the requests, the public route cannot be reached. 这意味着404路由捕获所有请求,无法到达公共路由。 You have to mount the handlers in the right order: 您必须按正确的顺序安装处理程序:
app.use(express.static('public'));
app.use(indexRoute);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.