未加载 ejs (Node.js) 的静态文件
我的静态文件未加载 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: