【问题标题】:Node JS newbie: why do I get a 404? (angular-seed)Node JS 新手:为什么我会得到 404? (角种子)
【发布时间】:2013-07-15 05:34:00
【问题描述】:

我是第一次尝试 NodeJS。 我正在遵循https://github.com/angular/angular-seed 和https://github.com/thedigitalself/angular-sprout 的hello world 指令(对于第一个稍微修改的fork,它具有相同的hello world 指令)。

在这两种情况下,我都应该使用 Node 运行包含在 repo 中的 web-server.js 文件,然后导航到 http://localhost:<port>/app/index.html

这给了我一个 404 错误页面(写在 web-server.js 文件中),就像 /app/ 一样。

但是,如果我导航到http://localhost:<port>,我会得到一个包含 web-server.js 脚本所在的文件系统目录的目录列表,该脚本也是用 web-server.js 编写的。

知道为什么 web-server.js 找不到 /app/ 或 /app/index.html 吗?

【问题讨论】:

  • 当我分叉并将存储库克隆到我的目录并运行 node script/web-server.js 并访问此链接 http://localhost:8000/app/index.html#/view1 它对我有用
  • 嗯,那个 URL 给了我同样的错误。
  • 仅供参考,不确定这是否相关,但如果我在脚本中运行 node script/web-server.js 或 cd 并运行 node web-server.js 而不仅仅是 ./web-server.js,节点退出并出现无法找到文件的错误web-server.js
  • 我通过运行 OSX 安装程序获得节点,成功退出。

标签: node.js angularjs


【解决方案1】:

确保从根目录运行服务器。

~/angular-seed/

在这里你可以node scripts/web-server.js

然后就可以访问了

http://localhost:<PORT>/app/index.html

【讨论】:

  • 这很奇怪,因为当我 cd 到 scripts 并运行 web-server.js 时,我会得到 404,但是当我回到根目录并运行 script/web-server.js 然后访问这个 localhost:8888/ 然后我获取目录列表,然后我可以去app 找到index.html 并没有问题。
  • 你有答案,但对我来说失败了,因为你写的是“script/”而不是文件夹名称“scripts/”。请编辑您的答案。
猜你喜欢
  • 2013-03-08
  • 1970-01-01
  • 1970-01-01
  • 2018-01-03
  • 2016-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多