Skip to content

Commit

Permalink
Merge pull request #29 from kenriortega/development
Browse files Browse the repository at this point in the history
Development UI and API
  • Loading branch information
kenriortega authored Nov 6, 2021
2 parents 58851d3 + 038d58a commit 62675a7
Show file tree
Hide file tree
Showing 34 changed files with 3,156 additions and 75 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/release.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ archives:
windows: Windows
386: i386
amd64: x86_64
files:
- docs/*
- README.md
- ngonx.yaml
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
133 changes: 126 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

It`s a simple proxy server written with [go](https://github.com/golang/go).
The core services are based on [nginx](https://github.com/nginx) server, and [traefik](https://github.com/traefik/traefik)
Our roadmap you can find here [project board](https://piqba.notion.site/f98799ba3d384526ac6591247b12481c?v=4ca0c832682749e99dcc72a66fdd71a1)

## Features

Expand All @@ -11,15 +12,12 @@ The core services are based on [nginx](https://github.com/nginx) server, and [tr
* Run ngonx as a static web server
* Project collaborative and open source

## **nGOnx** commands
## Download ngonxctl

> Build
Go to last release and download [ngonxctl](https://github.com/kenriortega/ngonx/releases) binary for you OS

```bash
make compile
```
## **nGOnx** commands

> List of command available

```bash
ngonxctl -h
Expand Down Expand Up @@ -50,7 +48,27 @@ Use "ngonxctl [command] --help" for more information about a command.

```

> Yaml file fields
> Setup cmd
Create the yaml file that contain a generic data

```bash
Create configuration file it`s doesn`t exist

Usage:
ngonxctl setup [flags]

Flags:
-h, --help help for setup

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```

> Yaml file with generic data

```yaml
# Static web server like nginx
Expand Down Expand Up @@ -104,8 +122,45 @@ proxy:
path_protected: true
```
> Version cmd show Build Time, version hash and version for the current binary
```bash
Print the version number of ngonxctl

Usage:
ngonxctl version [flags]

Flags:
-h, --help help for version

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```


> Start Proxy server first time
```bash
Run ngonx as a reverse proxy

Usage:
ngonxctl proxy [flags]

Flags:
--genkey Action for generate hash for protected routes
-h, --help help for proxy
--port int Port to serve to run proxy (default 5000)
--prevkey string Action for save a previous hash for protected routes to validate JWT

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```

`genkey` command in true generate random secretkey and save on badgerdb on `badger.data`

```bash
Expand All @@ -126,17 +181,65 @@ proxy:

> Start load balancer
```bash
Run ngonx as a load balancer (round robin)

Usage:
ngonxctl lb [flags]

Flags:
--backends string Load balanced backends, use commas to separate (default "ngonx.yaml")
-h, --help help for lb
--port int Port to serve to run load balancing (default 4000)

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```


```bash
./ngonxctl lb --backends "http://localhost:5000,http://localhost:5001,http://localhost:5002"
```
> Start static files server
```bash
Run ngonx as a static web server

Usage:
ngonxctl static [flags]

Flags:
-h, --help help for static

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```

```bash
./ngonxctl static
```

> Start grpc proxy server
```bash
Run ngonx as a grpc proxy

Usage:
ngonxctl grpc [flags]

Flags:
-h, --help help for grpc

Global Flags:
-f, --cfgfile string File setting.yml (default "ngonx.yaml")
-p, --cfgpath string Config path only (default "path/binary")

```

```bash
./ngonxctl grpc
```
Expand All @@ -160,7 +263,21 @@ Currently ngonx use port 10001 for export a simple api to check all services
curl http://localhost:10001/api/v1/mngt/
```

Method | Path |
---------|----------------
GET | /
GET | /health
GET | /readiness
GET | /wss

UI on `http://localhost:10001/`

![Service Discovery](/docs/service1.jpeg)
![Service Discovery](/docs/service2.jpeg)


How to interact with app for testing reasson
-----

> Start API PoC service
Expand Down Expand Up @@ -237,6 +354,8 @@ certbot renew
---


> Yaml file fields
BenchMarking
------------

Expand Down
34 changes: 25 additions & 9 deletions cmd/cli/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"embed"
"io/fs"
"net/http"
"net/url"
"os"
Expand All @@ -14,9 +16,13 @@ import (
"github.com/kenriortega/ngonx/pkg/healthcheck"
"github.com/kenriortega/ngonx/pkg/httpsrv"
"github.com/kenriortega/ngonx/pkg/logger"
"github.com/rs/cors"
"github.com/spf13/cobra"
)

//go:embed ui
var frontend embed.FS

// Middleware CORS
func CORSMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -71,6 +77,14 @@ func initConfig() {
}

func StartMngt(config config.Config) {

stripped, err := fs.Sub(frontend, "ui")
if err != nil {
logger.LogError(err.Error())
}

frontendFS := http.FileServer(http.FS(stripped))

r := mux.NewRouter()
repo := domain.NewMngtRepositoryStorage()
service := services.NewMngtService(repo)
Expand All @@ -87,16 +101,18 @@ func StartMngt(config config.Config) {
mh.RegisterEndpoint(endpointMap)
}
}
// Routes...
adminRoutes := r.PathPrefix("/api/v1/mngt").Subrouter()
adminRoutes.HandleFunc("/", mh.GetAllEndpoints).Methods(http.MethodGet)
adminRoutes.HandleFunc("/health", healthHandler)
adminRoutes.HandleFunc("/readiness", readinessHandler)

mngtAPI := r.PathPrefix("/api/v1/mngt").Subrouter()
mngtAPI.HandleFunc("/", mh.GetAllEndpoints)
mngtAPI.HandleFunc("/health", healthHandler)
mngtAPI.HandleFunc("/readiness", readinessHandler)
// Realtime options
adminRoutes.HandleFunc("/wss", mh.WssocketHandler)
r.Use(CORSMiddleware)
mngtAPI.HandleFunc("/wss", mh.WssocketHandler)

mgntWEB := r.PathPrefix("/")
mgntWEB.Handler(http.StripPrefix("/", frontendFS))
port := 10_001
cors.Default()
server := httpsrv.NewServer(
"0.0.0.0",
port,
Expand All @@ -106,7 +122,7 @@ func StartMngt(config config.Config) {
go func() {
t := time.NewTicker(time.Second * 30)
for range t.C {
// logger.LogInfo("Starting health check...")

endpoints, err := service.ListEndpoints()
if err != nil {
logger.LogError(err.Error())
Expand All @@ -124,7 +140,7 @@ func StartMngt(config config.Config) {
}
mh.UpdateEndpoint(it)
}
// logger.LogInfo("Health check completed")

}
}()

Expand Down
15 changes: 15 additions & 0 deletions cmd/cli/ui/assets/favicon.17e50649.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cmd/cli/ui/assets/index.7e4cf562.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 62675a7

Please sign in to comment.