【问题标题】:i am not able to include js file because of MIME(text/html) in node js由于节点 js 中的 MIME(text/html),我无法包含 js 文件
【发布时间】:2020-09-25 07:08:23
【问题描述】:

我正在尝试构建自己的 webrtc 平台,但由于此错误,我无法将 peer.js 文件包含到我的代码中。 来自“http://localhost:3000/peer.js”的脚本已加载,即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型。

这里是代码。


<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script>
    const ROOM_ID = "<%= roomId %>"
  </script>
  <script src="peer.js" defer></script>
  <script src="/socket.io/socket.io.js" defer></script>
  <script src="script.js" defer></script>
  <title>Document</title>
  <style>
    #video-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, 300px);
      grid-auto-rows: 300px;
    }
    
    video {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  </style>
</head>
<body>
  <div id="video-grid"></div>
</body>
</html>

【问题讨论】:

  • 使http://localhost:3000/peer.js 可访问的 Node.js 代码是什么样的?此外:您还可以强制浏览器将其视为正确的 mime 类型,使用 &lt;script src="peer.js" type="text/javascript" defer&gt;&lt;/script&gt;

标签: node.js webrtc


【解决方案1】:

peer.js 一个正确的路径,只提供名称将包含同一目录中存在的文件。

【讨论】:

    猜你喜欢
    • 2016-01-22
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多