开发过程中的npm http服务器和重写url

lan*_*oxx 5 npm

我正在寻找一种在开发过程中使用npm运行本地http服务器的方法。我已经看到了,http-server但还有一个附加要求。我需要使用代理将URL重写到后端应用程序。似乎http-server可以与npm一起安装的标准无法做到这一点。还有其他插件可以做到这一点吗?

本质上,我需要这样的东西:

# serve files in local folder, but rewrite all request
# to /api to localhost:8080/
npm run some-http-server --rewrite "/api/(.*) localhost:8080/$1" --path .
Run Code Online (Sandbox Code Playgroud)

因此,当我访问localhost/index.html服务器时,是本地index.html文件,但是当我访问localhost/api/foo它时,它将被重写为as localhost:8080/foo并将其代理到在port上运行的后端应用程序8080

这样的解决方案已经存在吗?

lan*_*oxx 9

看起来local-web-server npm软件包正是我想要的。

通过以下方式安装:

sudo npm install -g local-web-server
Run Code Online (Sandbox Code Playgroud)

Theb从以下开始:

ws -p 63342 -r '/api/*->http://localhost:8080/$1' -d myapp
Run Code Online (Sandbox Code Playgroud)