首页 文章

Nodejs服务器:无法加载资源:服务器响应状态为404(未找到)

提问于
浏览
0

我在节点中设置了一个Web服务器 .

var app = express();
app.use(express.static(PUBLIC_PATH));
server = require('http').createServer(app),
io = require('socket.io').listen(server);

我将公共路径设置为我的应用程序's root public folder, where i keep my frontend, so when the server is deployed, it' s / app / public

当我尝试打开页面时,我在chrome的控制台中看到了这一点

i无法加载资源:服务器响应状态为404(未找到)

有问题的文件是app.js,它位于我的公共文件夹中 . 我确实看到了Web服务器对该特定文件的请求

2015-04-04T15:43:04.208178 00:00 heroku [router]:at = info method = GET path =“/ style.css”host = hive-badescuga.herokuapp.com request_id = 2be0334e-e968-4397-8c2e -9c65c85fea22 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 6ms status = 304 bytes = 236 2015-04-04T15:43:04.203415 00:00 heroku [router]:at = info method = GET path =“/ app.js”host = hive-badescuga.herokuapp.com request_id = fc8c529c-7641-4df2-9b13-5fee9e1af365 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 7ms status = 404 bytes = 217 2015-04-04T15:43:09.152566 00:00 heroku [router]:at = info method = GET path =“/ style.css”host = hive-badescuga.herokuapp.com request_id = b89ded8e-5433-4b57-8c80 -c2e7407d31b0 fwd =“188.25.247.211”dyno = web.1 connect = 1ms service = 6ms status = 304 bytes = 236

问题是什么?

UPDATE

当我进一步调试时,我看到与我的app.js(无法加载)在同一根中的css被加载 . 这是我的HTML:

<link rel="stylesheet" href="/style.css">
<script type='text/javascript' src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script src="/app.js"></script>

所以style.css确实被加载而app.js没有(因为它找不到),并且它们在同一个文件夹中 .

2 回答

  • 0

    我不知道它是否有用,但可能你应该写:process.env.PUBLIC_PATH . 另外,我不知道你是否有这个:var express = require('express');

    我有这个:app.use(express.static(path.join(__ dirname,'views')));

  • 0

    所有都是固定的,如果app.js git被忽略,那么它在本地工作,但它没有上传 .

相关问题