1.0.2 • Published 7 years ago

quick-local-service v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

quick-local-service

快速启动静态web服务命令行程序

Build Status

当你编码了一个页面 index.html\other.html, 可以通过quick-local-service为这个页面启动web服务,以便在浏览器中通过 http://127.0.0.1:10086/index.html 来访问页面 (默认index.html)。 这样可以避免遇到直接双击打开页面时可能出现的跨域问题。

安装和使用

安装

$ npm install quick-local-service -g

进入项目目录,并启动服务

$ cd demo
$ qls run

默认端口: 10086

可以通过命令参数 -p 8989 设定端口.

另外,还可以使用命令参数 -d demo来指定项目路径.

$ cd demo
$ cd ..
$ qls run -d demo

配置文件

init 指令可以帮助在当前目录生成配置文件qls.config.js,这样run的时候会以配置文件为主,不再需要使用参数。

qls.config.js.

module.exports = {
	port:10086,
	dir:""
}

init会设置dir为当前目录路径。

另外,还可以通过参数指定配置文件 '-c other.config.js'

$ qls run -c other.config.js

配置跨域接口代理

在配置文件内 qls.config.js,定义proxy字段,例如:

module.exports = {
	port: 10086,
	dir: '',
	proxy:{
		'/api':{
			host:'http://127.0.0.1:8910',
			pathRewrite:{
				'^/api': '/api'
			}
		}
	}
}

在本项目的example目录有示例. (html/proxy.html qls run, service/other-proxy.js node other-proxy.js)

Todo:

  1. 配置模拟接口
  2. 完成 代理跨域接口
  3. 完成 识别端口被占用的情况
1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago