EJS:如何在EJS中正确链接样式表和JavaScript文件?
当使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您试图在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