简体   繁体   English

找不到Javascript 404资源NodeJS

[英]Javascript 404 Resource Not Found NodeJS

I'm running a Node JS server on an old laptop of mine, and I've portforwarded the port 8006 so that I can connect to the node server from another computer and view the web pages. 我正在我的旧笔记本电脑上运行Node JS服务器,并且将端口8006进行了端口转发,以便可以从另一台计算机连接到节点服务器并查看网页。 However, I have a sound file that I want the server to play when something happens, but after checking the console output on my computer, it keeps throwing this error: 但是,我有一个声音文件,我希望服务器在发生某些情况时播放,但是在检查计算机上的控制台输出后,它会不断抛出此错误:

GET http://0.0.0.0:8006/surprise.mp3 404 (Not Found) GET http://0.0.0.0:8006/surprise.mp3 404(未找到)

Where of course the zeroes are my actual IP address (the ip of the server). 当然零是我的实际IP地址(服务器的ip)。 Everything else runs fine including all the javascript files and the webpages. 一切正常,包括所有javascript文件和网页。 This is the code that actually plays the sound: 这是实际播放声音的代码:

var audio = new Audio('surpise.mp3');
audio.play();

And that's sitting inside one of the client-side javascript files. 这位于客户端javascript文件之一中。 How can I make that particular mp3 file accessible to outside users? 如何使外部用户可以访问该特定mp3文件?

If you're using the Express framework (which it sounds like you are), you can create a .get() route for /surprise.mp3 and then use res.SendFile("/somepath/surprise.mp3") so that your node.js server will serve that file when that route is requested. 如果您使用的是Express框架(听起来很像),则可以为/surprise.mp3创建.get()路由,然后使用res.SendFile("/somepath/surprise.mp3")以便请求该路由时,node.js服务器将提供该文件。

Or, if you have multiple static files to serve, you can use express.static() to set up a directory of static files that will get automatically served. 或者,如果要提供多个静态文件,则可以使用express.static()设置将自动提供服务的静态文件目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript-找不到错误404资源 - JavaScript - Error 404 resource not found 加载资源失败:服务器以 404(未找到)状态响应 nodejs - Failed to load resource: the server responded with a status of 404 (Not Found) with nodejs Node.js服务器:无法加载资源:服务器以状态404(未找到)响应 - Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found) 404 Not Found nodejs 到本地主机 - 404 Not Found nodejs to localhost 加载资源失败:服务器响应状态为 404(未找到) - JavaScript - Failed to load resource: the server responded with a status of 404 (Not Found) - JavaScript 加载资源失败:服务器在koa2和nodejs中以404(未找到)状态响应 - Failed to load resource: the server responded with a status of 404 (Not Found) in koa2 & nodejs NodeJS 不断获取加载资源失败:服务器响应状态为 404(未找到) - NodeJS keep getting Failed to load resource: the server responded with a status of 404 (Not Found) 找不到404 /服务器-Node.js Ajax - 404 /server Not Found - Nodejs Ajax 无法加载资源:服务器响应状态为404(未找到)javascript / application.js - Failed to load resource: the server responded with a status of 404 (Not Found) javascript/application.js 加载资源失败:服务器响应状态为 404(未找到) - javaScript CSS 文件 - Failed to load resource: the server responded with a status of 404 (Not Found) - javaScript CSS files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM