我已經在heroku上部署了我的應用程式。使用 Node.js Express ejs。
但由于某種原因,它沒有加載我的 CSS。
錯誤:
Unchecked runtime.lastError: The message port closed before a response was received.Refused to apply style from 'https://**.herokuapp.com/public/css/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.Failed to load resource: the server responded with a status of 404 (Not Found)
這些是我得到的錯誤。當我檢查頁面時。
我的檔案結構: 檔案結構
app.js 代碼
const express = require("express");
const bodyParser = require("body-parser");
const date=require(__dirname "/date.js");
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
header.ejs 代碼
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>TO-DO LIST</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" >
</head>
請有人幫我解決這個問題。
編輯 :
- 上述錯誤(1 和 3)不是由代碼引起的。它們是由于我的瀏覽器添加了擴展。
- 洗掉擴展后,錯誤 1 ??和錯誤 3 消失了。但錯誤 2 仍然存在。
uj5u.com熱心網友回復:
經過嚴格的研究和嘗試了很多方法,我終于能夠自己解決我的問題。
我做了一些重大更改,我的問題得到了解決。
我稍微改變了我的檔案結構。
從這里到這里
我在 views 目錄中創建了一個名為 partials 的新目錄,并將我的 header.ejs 和 footer.ejs 檔案移動到該目錄。
在 header.ejs 檔案中,我已經更改了代碼
-
<link href="css/styles.css" rel="stylesheet" type="text/css" >到
<link href="/css/styles.css" rel="stylesheet" type="text/css" > 在其他 .ejs 檔案中,我包含了 header.ejs 和 footer.ejs,如下所示:
<%- include("partials/header"); -%> <%- include("partials/footer"); -%>
這就是我能夠解決我的問題的方式。
哈庫納瑪塔塔
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/479927.html
上一篇:如何通過multer將影像上傳到HerokuApp而不會丟失?
下一篇:如何將影像檔案上傳到heroku
