CasaOS-Gateway

command module
v0.3.5-alpha5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

README

CasaOS-Gateway

Go Reference Go Report Card goreleaser

CasaOS Gateway is a dynamic API gateway service that can be used to expose APIs from different other HTTP based services.

This gateway service comes with a simple management API for other services to register their APIs by route paths. A HTTP request arrived at gateway port will be forwarded to the service that is registered for the route path.

As a best practice, a service behind this gateway should bind to localhost (127.0.0.1 for IPv4, ::1 for IPv6) ONLY, so no external network access is allowed.

Build / Install

$ make # build
...
$ sudo make install # copy built files to system, then enable service.
...
$ sudo make uninstall # disable service and remove from system.
...
$ make clean # remove built files.
...

Configuration

Upon launching, it will search for gateway.ini file in the following order:

./gateway.ini
./conf/gateway.ini
$HOME/.casaos/gateway.ini
/etc/casaos/gateway.ini

See gateway.ini.sample for default configuration.

Running

Once running, gateway address and management address will be available in the files under RuntimePath specified in configuration.

$ cat /var/run/casaos/gateway.url 
[::]:8080 # port is specified in configuration

$ cat /var/run/casaos/management.url 
[::]:34703 # port is randomly assigned

Example

Assuming that

  • the management API is running on port 34703
  • the gateway is running on port 8080
  • some API running at http://localhost:12345/ping that simply returns pong.

Then register the API as follows:

  • POST http://localhost:34703/v1/gateway/routes

    {
            "path": "/ping",
            "target": "http://localhost:12345"
    }
    

    or in command line:

    $ curl 'localhost:34703/v1/routes' --data-raw '
        {"path": "/ping", "target": "http://localhost:12345"}
      '
    

Now run

$ curl localhost:8080/ping
{"message":"pong"}

... which is equivalent as

$ curl localhost:12345/ping
{"message":"pong"}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
The commmon package provides structs and functions for external code to interact with this gateway service.
The commmon package provides structs and functions for external code to interact with this gateway service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL