![](/img/trans.png)
[英]socket.io-stream facing 404 issue when accessing in socket client and server also
[英]socket.io-stream 404 (Not Found)
我已經將socket.io-stream安裝到我的項目目錄中的node_modules文件夾中,但是當我調用時:
<script type="text/javascript" src="scripts/socket.io-stream.js"></script>
我在控制台中收到以下錯誤:
localhost/:14 GET http://localhost:3000/socket.io-stream.js 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:3000/socket.io-stream.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
我該怎么解決? 我已經檢查以確保它位於正確的目錄中,並且沒有運氣將其移至其他目錄。
我在其中的文件是HTML文件,而不是Node js,因此我無法使用express。
默認情況下,NodeJS不向客戶端提供服務器端文件。 如果這樣做的話,人們可以訪問您的整個代碼庫,包括配置等,這樣就不好了。 取而代之的是,您必須處理作為事件的http
模塊中出現的請求,並使用文件內容對其進行答復。 為此,您可能需要安裝著名的Express模塊( npm install --save express
)並使用其靜態文件服務:
const Express = require("express");
const app = Express();
app.use(Express.static(__dirname + "/somestaticfolder"));
app.listen(80);
現在,只需將文件放入/somestaticfolder
中即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.