[英]404 not found fetching static files from nodejs/connect.static('../angularjs')
I've seen another question here on SO, but I can't for the life of my figure out why I can't get this to work. 我在这里已经看到了另一个有关SO的问题,但是我无法理解为什么我无法解决这个问题。 In the same directory as my node installation I ran the commands npm install
and npm install connect
. 在与节点安装相同的目录中,我运行了命令npm install
和npm install connect
。 Then again in the same directory as my node installation I created a server.js file: 然后再次在与节点安装相同的目录中创建一个server.js文件:
var connect = require("connect");
var app = connect.createServer().use(connect.static('../angularjs'));
app.listen(8180);
so when then I'm again in my root node directory I do node server.js
to start the server and it starts fine. 所以当我再次进入根节点目录时,我执行node server.js
来启动服务器,并且启动正常。 In the root directory of node I made a folder called angularjs and in that folder I placed an index.html. 在节点的根目录中,我创建了一个名为angularjs的文件夹,并在该文件夹中放置了index.html。 Whenever I navigate in my browser to localhost:8180/index.html I get the message Cannot GET /index.html
. 每当我在浏览器中导航到localhost:8180 / index.html时,都会收到消息Cannot GET /index.html
。 It seems that this should be working, what in the world am I missing here? 看来这应该可行,我在这里想念什么呢?
Be careful about where the directory is. 请注意目录的位置。 From reading your post it appears that you have a node source directory that contains the angularjs directory, so that's what I created when testing. 通过阅读您的文章,您似乎拥有一个包含angularjs目录的节点源目录,这就是我在测试时创建的目录。
On Linux, you can examine the directory and what files are in it with the ls
or ls -l
(verbose) commands 在Linux上,您可以使用ls
或ls -l
(详细)命令检查目录及其中的文件
Works here with connect.static()
parameter ./angularjs
and does not work with ../angularjs
在这里使用connect.static()
参数./angularjs
,而不适用于../angularjs
Test procedure 测试程序
$ mkdir nodetest
$ cd nodetest
$ mkdir angularjs
$ cat >server.js <<EOF
var connect = require("connect");
var app = connect.createServer().use(connect.static('../angularjs'));
app.listen(8180);
EOF
$ npm install connect
$ emacs ./angularjs/test.html # make a html file to get
$ nodejs ./server.js &
$ wget http://localhost:8180/test.html
# fails 404
$ kill %1 // kill nodejs
$ emacs ./server.js # change ../angularjs to ./angularjs
$ nodejs ./server.js &
$ wget http://localhost:8180/test.html
# works
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.