EJS:如何在EJS中正确链接样式表和JavaScript文件?

发布于 2025-01-18 08:43:19 字数 461 浏览 1 评论 0原文

当使用EJS链接外部样式表和脚本标签时,我已经遇到了问题。这是我的样式表的链接。

<link rel="stylesheet" href="styles/index.css">

当我突出显示表格的链接并遵循(在VSCODE中),我将被带到正确的文件中。我知道它肯定会到正确的位置。

但是,当我在本地主机上运行此操作时:5000我会遇到错误。这是错误读取的内容。

拒绝从'http:// localhost:5000/styles/index.css'应用样式,因为其MIME类型('text/html')不是受支持的样式表MIME类型,并且启用了严格的MIME检查。

我注意到这指向我的本地主机:5000/styles/index.css,但我不希望它指向我的本地主机,我希望它指向我在文件结构中设置的目录。

有人知道如何解决这个问题吗?

非常感谢您的宝贵时间。

I have ran into an issue when using ejs to link external stylesheets and script tags. Here is my link for my stylesheet.

<link rel="stylesheet" href="styles/index.css">

When I highlight the link to the sheet and follow it (in VScode) I am brought to the correct file. I know it is going to the correct location for sure.

However, when I run this on my localhost:5000 I get an error. Here is what the error reads.

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

I notice this is pointing to my localhost:5000/styles/index.css, but I do not want it to point to my local host, I want it to point to the directories I have set up in my file structure.

Does anyone know how to resolve this?

Thank you so much for your time.

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

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

发布评论

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

评论(1

很糊涂小朋友 2025-01-25 08:43:19

如果您试图在nodejs项目中使用Express中使用EJS,则U首先定义一个包含所有静态文件(如CSS和图像)的文件夹,然后授予浏览器的权限以获取此文件。检查此文件:
https://expressjs.com/en/en/starter/static-files.html

if u are trying to use ejs in a nodejs project with express ,u should first define a folder that contain all the static files like css and images then give permission to the browser to get this file .check this:
https://expressjs.com/en/starter/static-files.html

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