节点/连接问题对象函数createServer没有方法静态[重复]

时间:2021-07-25 22:45:40

This question already has an answer here:

这个问题在这里已有答案:

I'm trying to launch my node server using an example from an AngularJS book (server.js).

我正在尝试使用AngularJS书籍(server.js)中的示例启动我的节点服务器。

var connect = require('connect');
connect.createServer(
connect.static("../angularjs")
).listen(5000);

Initially I was getting "object has no method static" so I re-installed the connect include and now when I do: node server.js I get a blinking cursor in CMD (Windows) and "Cannot GET /" from my browser.

最初我得到“对象没有方法静态”,所以我重新安装了connect include,现在当我这样做:node server.js我在CMD(Windows)中获得了一个闪烁的光标,并且从我的浏览器中获得了“Can not GET /”。

Any ideas folks?

有什么想法吗?

Thanks!

谢谢!

1 个解决方案

#1


5  

Your application is working just fine. You just need to specify the name of the file you want to access from static folder in the URL. For example if you have a file called app.html you need to access it via:

您的应用程序运行正常。您只需要在URL中指定要从静态文件夹访问的文件的名称。例如,如果您有一个名为app.html的文件,则需要通过以下方式访问它:

http://localhost:5000/app.html

Note that if you just use root URL, it will cause connect to look for default file name, which defaults to index.html. You can change that by passing new default file name in options:

请注意,如果您只使用根URL,则会导致connect查找默认文件名,默认为index.html。您可以通过在选项中传递新的默认文件名来更改它:

connect.static("../angularjs", {default: "app.html"});

#1


5  

Your application is working just fine. You just need to specify the name of the file you want to access from static folder in the URL. For example if you have a file called app.html you need to access it via:

您的应用程序运行正常。您只需要在URL中指定要从静态文件夹访问的文件的名称。例如,如果您有一个名为app.html的文件,则需要通过以下方式访问它:

http://localhost:5000/app.html

Note that if you just use root URL, it will cause connect to look for default file name, which defaults to index.html. You can change that by passing new default file name in options:

请注意,如果您只使用根URL,则会导致connect查找默认文件名,默认为index.html。您可以通过在选项中传递新的默认文件名来更改它:

connect.static("../angularjs", {default: "app.html"});