In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use http-server", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "http-server how to use"!
application scenarios
1. local area network access static pages
Access to files in the local computer is based on the file protocol. If we want to open our local files to people on the local area network, we cannot use the file protocol. Use HTTP or FTP protocol. http-server based on http protocol is a good choice
2. Handling pages across domains
When the page contains cross-domain requests, you can use http-server to use the command
http-server -p 8080 -P https://abc.org
//-p Local Run Port-P Proxies all requests that cannot be resolved locally to a given URL for processing
3. Verify that the front-end page is packaged normally
Many of the current projects are separated from the front and back. The front end usually packs the dist file and throws it to the test or other environment. We can use http-server to run the contents of the packaged dist directory and verify whether the packaged contents are correct.
installation
Preconditions for installation
Because http-server depends on node.js, make sure that node.js is installed in your environment before installing it. can be ordered
node -v
Verify node.js is installed
Install via npm
npm install http-server -g
Note: If you find that the installation is too slow during the installation process, you can configure the Taobao image first and then install it. The commands to configure mirroring are as follows
npm config set registry https://registry.npm.taobao.org
After configuration, you can verify whether it is successful by the following methods
npm config get registry
usage
http-server [path] [options]
path is the name of a folder corresponding to the command you are currently running
available options
-p or-port The port to use (default is 8080)
-a Address to use (default is 0.0.0.0)
-d Display directory list (default is true)
-i Display autoIndex (default is true)
-g or-gzip When enabled (default is false), it will./ public/some-file.js.gz instead of./ public/some-file.js When a gzip compressed version of the file exists and the request accepts gzip encoding.
-e or-ext if default file extension is not provided (default is html)
-s or-silent Suppress log messages from output
-cors Enable CORS via Access-Control-Allow-Origin header
-o Open browser window after starting server
-c Sets the cache control max-age header cache time in seconds, for example-c1010 seconds (default is 3600). To disable caching, use-c-1.
-U or-utc Use UTC time format in log messages.
-P or-proxy all requests that cannot be resolved locally to the given URL. For example: -P http://someurl.com
-S or-ssl enables https.
-C or-certssl path to cert file (default:) cert.pem.
-K or-keyssl Path to the key file (default:) key.pem.
-r or-robots provides/robots.txt (its content defaults to User-agent: *\nDisallow: /)
-h or-help Print this list and exit.
example
Go to the destination folder and type hs or http-server, but the following command is recommended
http-server -c-1
If you just type http-server, the page will not update synchronously after updating the code.
At this point, I believe that everyone has a deeper understanding of "how to use http-server", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.