Vhoster is a library for creating virtual hosts in a Go server. It is intended
to be used as a library, but it also includes a gateway that can be used to
create and delete vhosts dynamically.
The gateway can also be used as a central point of entry for all requests, and
it can be used to load balance requests to multiple servers.
then, to test, run curl test.localhost:8081, and you'll get the "Hello, World!"
Delete the vhost in the gateway
curl -X DELETE localhost:8083/vhost/test
In docker compose
Run docker compose up, it will build and start two container: (a) the
gateway on port 8080 and vhost api on port 8083, and (b) the test server on
port 8082, but the testserver is unreachable from the local machine
directly. We will set up a virtual host to access it.
If you want to verify that testserver is not accessible, try running curl localhost:8082 and you'll get an error.
It comes with preconfigured vhost "test.localhost:8080" that routes to
"http://testserver:8082". You can verify that it works by running curl test.localhost:8080, and you'll get the "Hello, World!"
Run the following command to instruct gateway to route all requests to
"hello.localhost:8080" to "http://testserver:8082":