Before installing, some configurations are required on the API. Inside the api/ folder, there is a folder called configs-example/. This folder contains an example of all configurations required.
Copy all configuration files to a new directory called config/. This new directory must be placed on the root of the api project.
Configuration files explanation:
- oauth.json - oauth server configuration (domain, port, endpoint)
- services.json - All microservices registered on the api management. (this can be replaced with mongodb)
- gAPI.json
- Authentication - user and password configuration to access admin area;
- TokenExpirationTime - time for the token to expire. Min value = 30s
- TokenSigningKey - Signing key for the token. Min length = 10
- LDAP - Ldap related configuration
- Active - If LDAP is enabled on gAPI or not
- Domain - Ldap server
- Port - Ldap Port (default: 389)
- Logs - activate/deactivate logs and type of logging (available: Elastic or Rabbit)
- CORS - AllowedOrigins (array with all allowed origins) and AllowCredentials
- ServiceDiscovery - configuration storage type (available: file and mongo) - note that when it is being used mongo, you MUST specify MONGO_HOST and MONGO_DB environment variables.
- Urls - Base urls for some of the services available on gAPI api:
- SERVICE_DISCOVERY_GROUP - service discovery base url
- ANALYTICS_GROUP - analytics base url
- Healthcheck - Healthcheck configuration
- Active - boolean to activate or deactivate healthcheck monitoring
- Frequency - Frequency in seconds at which monitor is done
- Notification - Enable or disable notifications when service goes down.
- Notifications
- Type - Notification type. Available options:
- Slack
- Slack - Slack notifications configuration.
- WebhookUrl - URL to POST notifications to
- Type - Notification type. Available options:
- Protocol
- Https - boolean to active or deactivate HTTPS
- CertificateFile - certificate file location
- CertificateKey - certificate key file location
- Plugins
- Location - where plugins are stored
- BeforeRequest - list of BeforeRequestPlugin type plugins
- Plugins
- Location - where plugins are stored
- BeforeRequest - list of BeforeRequestPlugin type plugins
- ThirdPartyOAuth
- Host - third party oauth host (ex: http://localhost)
- Port - third party oauth port
- AuthorizeEndpoint - authorization url (ex: /oauth/authorize)
- UserTokenInformation - if oauth return information about the token, specify where to retrieve it
- Active
- Source - where to fetch information from (ex: header)
- Name - Information name (ex: user)
- Authentication - user and password configuration to access admin area;
- users.json - Users registered on the system to access dashboard
gAPI is composed by six parts:
- gAPI Server
- Environment Variables
- Run
- gAPI Dashboard
- Environment Variables
- Run
- gAPI rabbit listener - only required when using RabbitMQ for queueing logs storage
- Environment Variables
- Run
- Elasticsearch - logs storage
- RabbitMQ - used as queue for logs (optional)
- MongoDB - used as service discovery storage engine (optional)
gAPI also can be run using docker:
- Docker
- Environment Variables
- Specify gAPI Server port:
API_MANAGEMENT_PORT=<new port> (default: 8080)
- Enable live analytics:
SOCKET_PORT=<socket port>
- Elasticsearch is required for logging requests:
ELASTICSEARCH_HOST=<elastic host>
ELASTICSEARCH_PORT=<elastic port>
- To use RabbitMQ as queueing system for logging:
RABBITMQ_HOST=<rabbit host>
RABBITMQ_PORT=<rabbit port> (default: 5601)
RABBITMQ_USER=<rabbit user>
RABBITMQ_PASSWORD=<rabbit password>
RABBITMQ_QUEUE=<rabbit gapi queue name>
- Use MongoDB as service discovery storage engine:
MONGO_HOST=<mongodb host>
MONGO_DB=<mongodb database name>
- Service discovery is a separate service:
SERVICEDISCOVERY_HOST=<custom SD host>
SERVICEDISCOVERY_PORT=<custom SD port>
To run gAPI Server, follow this steps:
- Copy the project to go/src folder
- Compile the code using the command:
go build -o server ./server.go
- Start the server using the following command:
./server
gAPI Rabbit Listener requires the following environement variables:
RABBITMQ_HOST=<rabbit host>
RABBITMQ_PORT=<rabbit port> (default: 5601)
RABBITMQ_USER=<rabbit user>
RABBITMQ_PASSWORD=<rabbit password>
RABBITMQ_QUEUE=<rabbit gapi queue name>
ELASTICSEARCH_HOST=<elastic host>
ELASTICSEARCH_PORT=<elastic port>
These environment variables must go along with the ones specified on gAPI server.
- Copy the project to go/src folder
- Compile the code using the command:
go build -o rabbit-listener ./rabbit-listener.go
- Start the listener using the following command:
./rabbit-listener
All commands regarding the dashboard, must be run inside dashboard/ folder.
Some environment variables are required to build the dashboard. Env vars are located in .env.{ENV_NAME} files.
These are the required env vars:
API_HOST=<gAPI host>
API_PORT=<gAPI port>
SOCKET_HOST=<gAPI socket host>
SOCKET_PORT=<gAPI socket port>
To start the dashboard, follow this steps:
- Install all dependencies:
npm install
- Build the sources:
npm run build
- Start the service
node index.js
gAPI can also be run using docker compose.
To run all gAPI dependencies, just run the following command on the root of the project:
docker-compose up -d
When using docker, all environment variables have default values already which allow to start all services without any configuration. If you want to customize it, you can override the following environment variables:
- API_MANAGEMENT_PORT=${API_MANAGEMENT_PORT:-8080}
- RABBITMQ_HOST=${RABBITMQ_HOST:-rabbit}
- RABBITMQ_PORT=${RABBITMQ_PORT:-5672}
- RABBITMQ_USER=${RABBITMQ_USER:-gapi}
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD:-gapi}
- RABBITMQ_QUEUE=${RABBITMQ_QUEUE:-gAPI-logqueue}
- ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST:-elastic}
- ELASTICSEARCH_PORT=${ELASTICSEARCH_URL:-9200}
- SERVICEDISCOVERY_HOST=${SERVICEDISCOVERY_HOST:-localhost}
- SERVICEDISCOVERY_PORT=${SERVICEDISCOVERY_PORT:-8080}
- MONGO_HOST=${MONGO_HOST:-mongodb}
- MONGO_DB=${MONGO_DB:-gapi}
- SOCKET_PORT=${SOCKET_PORT:-5000}