未加载 ejs (Node.js) 的静态文件

发布于 2025-01-10 09:05:27 字数 1089 浏览 0 评论 0原文

我的静态文件未加载 ejs。我收到以下错误。我已经尝试了多种方法来加载静态数据,但仍然遇到以下错误,

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

info-order:63 GET http://localhost:8080/js/order.js net::ERR_ABORTED 404 (Not Found)

info-order:1 Refused to apply style from 'http://localhost:8080/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

我的配置文件具有以下代码。

const express = require("express");
const path = require("path");

/*config view engine*/

let configViewEngine = (app) => {
  app.use(express.static(path.join(__dirname + "./src/public")));

  app.set("viewEngine", "ejs");
  app.set("views", "./src/views");
};
module.exports = configViewEngine;

并且我已链接样式表,如下所示。

<link rel="stylesheet" href="/css/style.css" />

我在 ejs 上的脚本标记如下..

<script src="/js/order.js"></script>

my static files are not loading for ejs. I get following error. I have tried in several ways to get loaded the statics but still I'm getting following errors

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

info-order:63 GET http://localhost:8080/js/order.js net::ERR_ABORTED 404 (Not Found)

info-order:1 Refused to apply style from 'http://localhost:8080/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

my config file has following code..

const express = require("express");
const path = require("path");

/*config view engine*/

let configViewEngine = (app) => {
  app.use(express.static(path.join(__dirname + "./src/public")));

  app.set("viewEngine", "ejs");
  app.set("views", "./src/views");
};
module.exports = configViewEngine;

And I have link the stylesheet as follow.

<link rel="stylesheet" href="/css/style.css" />

my script tag on ejs as foillow..

<script src="/js/order.js"></script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2025-01-17 09:05:27

试试这个:

app.use(express.static(path.join(__dirname, 'src/public')));

Try this:

app.use(express.static(path.join(__dirname, 'src/public')));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文