【发布时间】:2015-06-09 12:07:10
【问题描述】:
我在 node 中设置了一个 Web 服务器。
var app = express();
app.use(express.static(PUBLIC_PATH));
server = require('http').createServer(app),
io = require('socket.io').listen(server);
我将公共路径设置为我的应用程序的根公共文件夹,我将我的前端保存在其中,所以当部署服务器时,它是 /app/public
当我尝试打开一个页面时,我在 chrome 的控制台中看到了这个
i 加载资源失败:服务器响应状态为 404 (未找到)
有问题的文件是 app.js,它位于我的 public 文件夹中。我确实看到了来自网络服务器对该特定文件的请求
2015-04-04T15:43:04.208178+00:00 heroku[路由器]: at=info method=GET path="/style.css" 主机=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[路由器]: at=info method=GET path="/app.js" 主机=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[路由器]: at=info method=GET path="/style.css" 主机=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
有什么问题?
更新
当我进一步调试时,我看到与我的 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 不会(因为找不到),并且它们在同一个文件夹中。
【问题讨论】:
标签: javascript node.js http heroku express