Front-end development tool http-server

In the development process, in many cases, it is necessary to run the project in serverthe environment .

Sometimes when we open a document using filethe protocol , we cannot send ajaxa request, and only use httpthe protocol to request resources, so at this time we need to create a local httpservice to access resources through IP plus port number.

http-serverIt is an ultra- nodejslightweight http webserver based on , http-serveryou can use any folder as a server directory for your own use, completely throwing away the heavy engineering in the background, and run your code directly.

When we want to run some code on the server, but we don't know how to configure the server, we can use http-serverto done. http-serveris a simple zero-config command-line httpserver that is powerful enough for production and use, for local testing and development.

install/update

git-bashOpen npm i http-server -gand enter to http-serverinstall :

npm i http-server -g

Parameter Description

-p Port to use (defaults to 8080)

-a Address to use (defaults to 0.0.0.0)

-d Show directory listings (defaults to 'True')

-i Display autoIndex (defaults to 'True')

-g or --gzip When enabled (defaults to 'False') it will serve ./public/some-file.js.gzin place of ./public/some-file.js when a gzipped version of the file exists and the request accepts gzip encoding.

-e or --ext Default file extension if none supplied (defaults to 'html')

-s or --silent Suppress log messages from output

--cors Enable CORS via the Access-Control-Allow-Origin header

-o Open browser window after starting the server

-c Set cache time (in seconds) for cache-control max-age header, e.g. -c10 for 10 seconds (defaults to '3600'). To disable caching, use -c-1.

-U or --utc Use UTC time format in log messages.

-P or --proxy Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com

-S or --ssl Enable https.

-C or --cert Path to ssl cert file (default: cert.pem).

-K or --key Path to ssl key file (default: key.pem).

-r or --robots Provide a /robots.txt (whose content defaults to 'User-agent: *\nDisallow: /')

-h or --help Print this list and exit.
-p 或者 --port 端口设置,默认是 8080
-a 监听地址设置默认是 0.0.0.0
-d 是否显示文件列表 默认true
-i 显示自动索引 默认true
-g 或者 --gzip 默认false,当文件的gzip版本存在且请求接受gzip编码时,它将服务于./public/some-file.js.gz,而不是./public/some-file.js
-e 或者 --ext 如果没有提供默认文件扩展名(默认为html)
-s 或者 --silent 禁止控制台日志信息输出
–cors 允许跨域资源共享
-o 启动服务后打开默认浏览器
-c 设置缓存cache-control max-age heade存留时间(以秒为单位),示例:-c10是10秒,默认是3600秒,如果要禁用缓存就使用-c-1
-U 或者 --utc 使用 UTC格式,在控制台输出时间信息
-P 或者 --proxy 通过一个 url地址,代理不能通过本地解析的资源

common operation

  • To disable caching, run the following command:
http-server -c-1
  • Enable cross domain cors
http-server --cors
  • specified port
http-server -p 9999
  • Open the browser after starting the service
http-server -o

—————————— [End of text] ——————————

Front-end learning exchange group, if you want to come in face-to-face, you can join the group: 685486827 , 832485817 ;
Vue learning exchange React learning exchange

Written at the end: convention is better than configuration - the principle of simplicity in software development

—————————— 【End】 ——————————

My:
Personal website: https://neveryu.github.io/neveryu/
Github: https://github.com/Neveryu
Sina Weibo: https://weibo.com/Neveryu

For more learning resources, please pay attention to my Sina Weibo... ok

Guess you like

Origin blog.csdn.net/csdn_yudong/article/details/122224674