默认情况下,如何在http服务器中提供index.html

Sau*_*ari 6 localhost httpserver angularjs

我已经在节点环境中创建了一个基本的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

我在这里做错了。

PS我参观了Angular JS种子,那里有官方的例子http-server -a localhost -p 8080 -c-1 ./app。但是,当我这样做时,我收到错误消息,尽管我的结构类似于种子,但Windows无法找到指定的路径

我的结构:

dir
   --app.js
   --index.html
   --node_modules
   --package.json
Run Code Online (Sandbox Code Playgroud)

Ell*_*ott 5

确保首先构建项目并生成输出./dist文件夹或类似文件夹。

然后试试这个命令:

http-server -p 8080 ./dist -o http://localhost:8080/index.html
Run Code Online (Sandbox Code Playgroud)

http://的网址中缺少。

  • 当请求“a_dir”时,“-o”将打开指定的文档,而不是提供“a_dir/index.html”。 (2认同)

PPB*_*PPB -1

尝试将静态文件放入新目录 public 中。并运行你的服务器http-server

- app.js
-public
--index.html
-package.json
Run Code Online (Sandbox Code Playgroud)