我在节点环境中创建了一个基本的AngularJS应用程序。我正在使用http-server模块将文件提供给浏览器。除了在服务器启动时默认无法提供index.html
这一事实外,一切正常。
我检查了npm注册表以获取更多http服务器模块的选项,并尝试在SO上查找相关问题,但仍然无法获得我想要的内容。
是否可以指定在服务器启动时提取的文件。
我的服务器基本上从localhost:8080
开始,而我希望localhost:8080/index.html
我的开始脚本是http-server -a localhost -p 8080 -c-1
。如果我执行类似http-server -a localhost -p 8080 -c-1 index.html
的操作,我会惊讶地打开index.html
文件但是在文件协议上提供,而不是在localhost
上提供。
我在这里做错了什么。
P.S。我访问了Angular JS种子,官方的例子说http-server -a localhost -p 8080 -c-1 ./app
。但是,当我这样做时,我收到错误 Windows无法找到指定的路径,尽管我的结构与种子类似。
我的结构:
dir
--app.js
--index.html
--node_modules
--package.json
答案 0 :(得分:0)
尝试将静态文件放在新目录public中。并运行服务器http-server
- app.js
-public
--index.html
-package.json

答案 1 :(得分:0)
确保首先构建项目并生成输出./dist
文件夹或类似文件夹。
然后尝试以下命令:
http-server -p 8080 ./dist -o http://localhost:8080/index.html
您在网址中缺少http://
。
答案 2 :(得分:0)
有人解决了吗?当我使用index.html输入完整地址时,它会打开,但是当我只http://localhost:8080时,什么都不会进来。
答案 3 :(得分:0)
添加-f /index.html
或任何文档。
以我为例:
http-server -c-1 -f /index.html