Nodejs 服务器:无法加载资源:服务器响应状态为 404(未找到)
Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found)
我在节点中设置了一个网络服务器。
var app = express();
app.use(express.static(PUBLIC_PATH));
server = require('http').createServer(app),
io = require('socket.io').listen(server);
我将 public 路径设置为我的应用程序的根 public 文件夹,其中我保留了我的前端,因此在部署服务器时,它是 /app/public
当我尝试打开一个页面时,我在 chrome 的控制台中看到了这个
i Failed to load resource: the server responded with a status of 404
(Not Found)
有问题的文件是 app.js,它位于我的 public 文件夹中。我确实看到了来自网络服务器的对那个特定文件的请求
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
问题是什么?
更新
当我进一步调试时,我看到 css 与我的 app.js(无法加载)位于同一根目录中,已加载。这是我的 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 没有(因为找不到),并且它们在同一个文件夹中。
我不知道它是否有帮助,但也许你应该写:
process.env.PUBLIC_PATH。另外,不知道你有没有这个:
var express = require('express');
我有这个:
app.use(express.static(path.join(__dirname ,'views')));
所有内容都已修复,忽略了 app.js git 所以它在本地工作但没有上传。
我在节点中设置了一个网络服务器。
var app = express();
app.use(express.static(PUBLIC_PATH));
server = require('http').createServer(app),
io = require('socket.io').listen(server);
我将 public 路径设置为我的应用程序的根 public 文件夹,其中我保留了我的前端,因此在部署服务器时,它是 /app/public
当我尝试打开一个页面时,我在 chrome 的控制台中看到了这个
i Failed to load resource: the server responded with a status of 404 (Not Found)
有问题的文件是 app.js,它位于我的 public 文件夹中。我确实看到了来自网络服务器的对那个特定文件的请求
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
问题是什么?
更新
当我进一步调试时,我看到 css 与我的 app.js(无法加载)位于同一根目录中,已加载。这是我的 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 没有(因为找不到),并且它们在同一个文件夹中。
我不知道它是否有帮助,但也许你应该写: process.env.PUBLIC_PATH。另外,不知道你有没有这个:
var express = require('express');
我有这个:
app.use(express.static(path.join(__dirname ,'views')));
所有内容都已修复,忽略了 app.js git 所以它在本地工作但没有上传。