Compare commits

...

6 commits

Author SHA1 Message Date
Simon Vieille 8f1f62787a
update changelog
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-29 17:08:28 +02:00
Simon Vieille 9deb71e082
allow to use a configuration file
parse .capture.ini

add information os start
2023-05-29 17:07:39 +02:00
Simon Vieille cd5d927e7a
update logo
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-29 11:58:13 +02:00
Simon Vieille 06a8ee8fe2
update documentation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-29 11:39:33 +02:00
Simon Vieille ef3a1d88dd
update documentation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-29 11:06:21 +02:00
Simon Vieille 4a3b19497f
replace the clear button with a SVG
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-29 10:58:44 +02:00
7 changed files with 464 additions and 412 deletions

View file

@ -1,5 +1,11 @@
## [Unreleased]
## v1.2.0
### Added
- allow to use a configuration file
- add logo
- replace the clear button with a SVG
## v1.1.0
### Added
- add query string in the request log

View file

@ -1,13 +1,14 @@
**Capture** is a reverse proxy that takes an incoming HTTP request and sends it to another server,
proxying the response back to the client, while showing them in a dashboard.
Forked from [ofabricio/capture](https://github.com/ofabricio/capture).
[![status-badge](https://ci.gitnet.fr/api/badges/deblan/capture/status.svg)](https://ci.gitnet.fr/deblan/capture)
## Running
```
./capture -url=https://example.com/
./capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
```
#### Settings
@ -20,6 +21,15 @@ proxying the response back to the client, while showing them in a dashboard.
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
You can create a file named `.capture.ini` and set the configuration inside:
```
url = https://example.com/
port = 9000
dashboard = 9001
captures = 16
```
## Using
If you set your base url as `http://example.com/api`, now `http://localhost:9000` points to that
@ -34,7 +44,7 @@ To access the dashboard go to `http://localhost:9001/`
##### Preview
![dashboard](https://upload.deblan.org/u/2023-05/6470ba9d.png)
![dashboard](https://upload.deblan.org/u/2023-05/64746afd.png)
## Building

View file

@ -2,6 +2,9 @@ package main
import (
"flag"
"fmt"
"gopkg.in/ini.v1"
"os"
)
// Config has all the configuration parsed from the command line.
@ -14,11 +17,36 @@ type Config struct {
// ReadConfig reads the arguments from the command line.
func ReadConfig() Config {
targetURL := flag.String("url", "https://jsonplaceholder.typicode.com", "Required. Set the url you want to proxy")
proxyPort := flag.String("port", "9000", "Set the proxy port")
dashboardPort := flag.String("dashboard", "9001", "Set the dashboard port")
maxCaptures := flag.Int("captures", 16, "Set how many captures to show in the dashboard")
defaultTargetURL := "https://jsonplaceholder.typicode.com"
defaultProxyPort := "9000"
defaultDashboardPort := "9001"
defaultMaxCaptures := 16
configFile := ".capture.ini"
if _, err := os.Stat(configFile); err == nil {
cfg, err := ini.Load(configFile)
if err != nil {
fmt.Printf("Fail to read file %s: %v", configFile, err)
os.Exit(1)
}
section := cfg.Section("")
defaultTargetURL = section.Key("url").MustString(defaultTargetURL)
defaultProxyPort = section.Key("port").MustString(defaultProxyPort)
defaultDashboardPort = section.Key("dashboard").MustString(defaultDashboardPort)
defaultMaxCaptures = section.Key("captures").MustInt(defaultMaxCaptures)
}
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
flag.Parse()
return Config{
TargetURL: *targetURL,
ProxyPort: *proxyPort,

View file

@ -2,8 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wd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9Ik0gMTQsMjEgSCA0IEEgMiwyIDAgMCAxIDIsMTkgViA1IEEgMiwyIDAgMCAxIDQsMyBoIDE2IGEgMiwyIDAgMCAxIDIsMiB2IDkiCiAgICAgICAgIHN0cm9rZT0iIzlhOTk5NiIKICAgICAgICAgc3Ryb2tlLXdpZHRoPSIyIgogICAgICAgICBzdHJva2UtbGluZWNhcD0icm91bmQiCiAgICAgICAgIGlkPSJwYXRoMjgiCiAgICAgICAgIHN0eWxlPSJzdHJva2U6I2I3YzRjODtzdHJva2Utd2lkdGg6MS4xMDc3OTtzdHJva2UtbWl0ZXJsaW1pdDo0O3N0cm9rZS1kYXNoYXJyYXk6bm9uZSIgLz4KICAgICAgPHBhdGgKICAgICAgICAgZD0iTSAyLDcgSCAyMiBNIDUsNS4wMSA1LjAxLDQuOTk5IE0gOCw1LjAxIDguMDEsNC45OTkgTSAxMSw1LjAxIDExLjAxLDQuOTk5IE0gMTkuNSwxNiB2IDYgbSAwLDAgTCAxNywxOS41IE0gMTkuNSwyMiAyMiwxOS41IgogICAgICAgICBzdHJva2U9IiM5YTk5OTYiCiAgICAgICAgIHN0cm9rZS13aWR0aD0iMiIKICAgICAgICAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogICAgICAgICBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgICAgICBpZD0icGF0aDMwIgogICAgICAgICBzdHlsZT0ic3Ryb2tlOiNiN2M0Yzg7c3Ryb2tlLXdpZHRoOjEuMTA3Nzk7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmUiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700" rel="stylesheet">
<title>Capture</title>
@ -220,10 +219,6 @@
}
.controls {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: .5rem;
justify-content: start;
}
button {
@ -246,17 +241,25 @@
background: var(--btn-hover);
}
.retry {
.button-svg {
padding: 0;
background: none;
}
.retry svg {
.button-svg svg {
width: 16px;
height: 16px;
}
.button-svg[disabled] svg {
opacity: 0.3;
}
.button-svg svg {
stroke: #9a9996;
}
.retry:hover svg * {
.button-svg:not([disabled]):hover svg * {
stroke: #fff;
}
@ -333,7 +336,9 @@
<div class="dashboard" id="app" v-cloak>
<div class="list">
<div class="controls">
<button :disabled="items.length == 0" @click="clearDashboard">clear</button>
<button class="button-svg" :disabled="items.length == 0" @click="clearDashboard">
<svg viewBox="0 0 24 24" stroke-width="3" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 9l-1.995 11.346A2 2 0 0116.035 22h-8.07a2 2 0 01-1.97-1.654L4 9M21 6h-5.625M3 6h5.625m0 0V4a2 2 0 012-2h2.75a2 2 0 012 2v2m-6.75 0h6.75" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</button>
</div>
<div class="list-inner">
<div class="list-item" v-for="item in items" :key="item.id" @click="show(item)"
@ -344,7 +349,7 @@
<span class="status" :class="statusColor(item)">
{{ item.status == 999 ? 'failed' : item.status }}
</span>
<button class="retry" @click="retry(item.id)">
<button class="button-svg" @click="retry(item.id)">
<svg stroke-width="3" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M21.888 13.5C21.164 18.311 17.013 22 12 22 6.477 22 2 17.523 2 12S6.477 2 12 2c4.1 0 7.625 2.468 9.168 6" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17 8h4.4a.6.6 0 00.6-.6V3" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</button>
</div>
@ -378,11 +383,9 @@
<span>Proxying {{ targetURL }}</span>
</p>
</div>
</div>
<script type="text/javascript">
var app = new Vue({
<script>
new Vue({
el: '#app',
data: {
items: [],

2
go.mod
View file

@ -1,3 +1,5 @@
module github.com/ofabricio/capture
go 1.16
require gopkg.in/ini.v1 v1.67.0 // indirect

2
go.sum
View file

@ -0,0 +1,2 @@
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

View file

@ -30,6 +30,7 @@ var dashboardHTML []byte
func main() {
cfg := ReadConfig()
fmt.Printf("Target is %s", cfg.TargetURL)
fmt.Printf("\nListening on http://localhost:%s", cfg.ProxyPort)
fmt.Printf("\nDashboard on http://localhost:%s", cfg.DashboardPort)
fmt.Println()