node.js http-server set up a local server

Use vue-cli creation of the project, enables the browser to automatically refresh, to view real-time program, but the principle is that, webpack locally started a local server, this machine as a server;

File after the package is a static html page, in a local folder opened directly are generally prime hifile agreement, when the link http or https existence of the code, html page will not open properly, in order to solve this situation, we need to local start to spoof the local server.

Node.js use of http-server enable local service, follow these steps:

First, the computer has been installed node.js, http-server installation

npm install http-server -g

Then enter the location you want as a local server root directory, execute the command htpp-server

Start the local server, you can use ctrl + c shut down the server

http-server -c-1 (after ⚠️ only enter http-server, then update the code, the page will not sync update)

Abbreviated hs

You can modify a server's listen address and listen port number

hs <path> -a 127.0.0.1 -p 8090

path is the list address, open cmd default directory address may be omitted, the default path open cmd address

-a parameter is listening address

-p parameter is listening on port

Other parameters

effect effect
-p or --port Port settings, the default is 8080
-a -a set the default listen address is 0.0.0.0
-d Whether to display a list of files by default true
-i The default display is automatically indexed true
-g or --gzip  Default false, and when there is a request to accept gzip encoding gzip version of the file, it will serve ./public/some-file.js.gz, rather than ./public/some-file.js
-e or --ext If no default file extension (default html)
-s or --silent  Prohibit the console log output
-cors Allowing cross-domain resource sharing
-O After starting the service to open the default browser
-c Set the cache cache-control max-age heade residence time (in seconds), Example: -c10 10 seconds, 3600 seconds by default, if it is used to disable caching -c-1
-U or --utc Use UTC format in the console output time
-P or --proxy  By a url address, the agent can not be resolved by local resources
-S or --ssl  Use the https protocol
Or -C --cert  Ssl certificate file path, default is cert.pem
-K or --key  ssl key file path
-h or --help  Display help



 




 

 


 





 

 

 

 

 

 

 

 

Reference: https://blog.csdn.net/ithanmang/article/details/88375259

 

Guess you like

Origin www.cnblogs.com/xiaofenguo/p/11315810.html