节点http服务器以index.html响应任何请求 [英] node http-server to respond with index.html to any request

查看:193
本文介绍了节点http服务器以index.html响应任何请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已全局安装http-server.

我从 myDir 在本地主机端口8080上启动它.在 myDir 中,我有index.html.

I launch it from myDir on localhost port 8080. In myDir I have index.html.

如果(从浏览器)请求http://localhost:8080/,我会得到index.html,这是可以的.

If I request (from the browser) http://localhost:8080/ I get index.html, which is OK.

如果我通过http://localhost:8080/anything请求,则不会从服务器得到任何响应.

If I request though http://localhost:8080/anything I do not get any response from the server.

相反,我想让我的服务器始终以index.html响应端口8080上到达localhost的任何http请求.

What I would like, on the contrary, is that my server always responds with index.html to any http request reaching localhost on port 8080.

这可能吗?

预先感谢

推荐答案

为实现您的要求,我建议您

To achieve what you are asking for, I recommend you live-server instead of http-server.

live-server --port=8080 --entry-file=./index.html

实时服务器还提供了热重载,但这不是您的请求之一

live-server is also providing a hot-reload but it was not one of your request

live-server不适用于生产环境.例如没有gzip压缩

live-server is not designed to be used in production. No gzip compression for example

http服务器的维护者在此明确表示在此评论,永远不会,http服务器会考虑SPA用例

Edit 2: The maintainer of http-server clearly said in this comment that never, http-server will consider the SPA use-cases

服务似乎也是一个不错的选择

Edit 3: serve seems to be a good option too

这篇关于节点http服务器以index.html响应任何请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆