The static HTTP service has several uses:

  • Static web page HTTP service to access browsing
    • For example: generated documents, blogs, etc
  • Expose files to HTTP service to access download
    • For example, shared documents and installation packages

Here are the two most recommended approaches I’ve seen so far:

  • Python: http.server — HTTP servers
  • Node.js: http-server: a command-line http server

Python: http.server — HTTP servers

This is available once you have Python installed.

First CD to the directory to expose, then execute:

$python -m HTTP. server 8000 Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)...Copy the code

Browser visit http://0.0.0.0:8000/ :

Node.js: http-server: a command-line http server

You need to install Node.js and then install the http-server package:

npm install -g http-server
Copy the code

Homebrew is also available on macOS in one step:

brew install http-server
Copy the code

After that, an HTTP-server command is added. CD to the directory you want to expose, execute:

$ http-server
Starting up http-server, serving ./
Available on:
  http://127.0.0.1:8080
  http://192.168.199.99:8080
Hit CTRL-C to stop the server
Copy the code

The browser to http://192.168.199.99:8080:

A comparison of the two approaches

Python: http.server

Reading the document, you can see:

Not applicable to products, simple function. However, the system is usually pre-installed with Python for temporary use.

Node.js: http-server

Reading the document, you can see:

Applicable to products, complete functions: HTTPS, GZIP, etc. It’s better to use this to hang the service out.

conclusion

Go coding!


Share practical tips and knowledge in Coding! Welcome to pay attention and grow together!