For the purpose of providing a web service to a Node.js project to users, we may require a small middleware to start an HTTP service to handle the HTTP requests.
In python, we can use http.server to start a web service.
python3 -m http.server
This command will return the corresponding files based on your requests.
Unfortunately, this does not work for a Node.js project. We may visit http://example.com/foo
, but the real target is /index.html. This will raise an unexpected 404 error.
Solution: webpack-dev-server, webpack-serve
These toolkits provided a very useful envoronment in developing. But not designed for the production.
We can also configure Nginx and could get a perfect result.
The configuration file is pretty easy
server {
listen 80;
server_name example.com;
root /path/to/the/project;
index index.html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
Therefore, we may also use another solution:
Recently, I prepared a small script based on golang. It will do the similar job as the behavior above in Nginx, but much smaller and efficacy.
If you just wish to use it, please just use the following command:
go get -v github.com/argcv/hou/cmd/hou
If you wish to make contributions to the repo, you can use the following script.
curl -L https://bit.ly/2KzJeU6 | bash
If you are using Chinese network, you may use aliyun's mirror: registry.cn-zhangjiakou.aliyuncs.com/yuikns/hou
Otherwise, you may use argcv/hou
from dockerhub.
Since the logic is very easy and the dependencies on very few packages, this image is only 6MB in the current.
Example of using Docker through docker-compose
A docker-compose.yml file is a YAML file that defines how Docker containers should behave in production.
Here is an example to use Hou easily
version: '3'
services:
hou:
image: argcv/hou:latest
ports:
- 6789:6789
restart: always
volumes:
# /app is the default root of the service
- ./dist:/app
# command: ["-d", "-v" ] # other options