Compare commits
4 commits
8f1f62787a
...
67ec75e6ea
Author | SHA1 | Date | |
---|---|---|---|
67ec75e6ea | |||
2c0904ff1a | |||
26f7c9c40e | |||
d1dd93ee23 |
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM debian:stable-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install ca-certificates -y
|
||||||
|
|
||||||
|
COPY ./capture /usr/bin/capture
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/capture"]
|
17
README.md
17
README.md
|
@ -13,13 +13,13 @@ Forked from [ofabricio/capture](https://github.com/ofabricio/capture).
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
|
||||||
| param | description |
|
| param | description |
|
||||||
|--------------|-------------|
|
| -------------- | ------------- |
|
||||||
| `-url` | **Required.** Set the url you want to proxy |
|
| `-url` | **Required.** Set the url you want to proxy |
|
||||||
| `-port` | Set the proxy port. Default: *9000* |
|
| `-port` | Set the proxy port. Default: *9000* |
|
||||||
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
||||||
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
||||||
|
| `-config` | Set the configuration file. Default: *.capture.ini* |
|
||||||
|
|
||||||
You can create a file named `.capture.ini` and set the configuration inside:
|
You can create a file named `.capture.ini` and set the configuration inside:
|
||||||
|
|
||||||
|
@ -37,10 +37,9 @@ address. Hence, calling `http://localhost:9000/users/1` is like calling `http://
|
||||||
|
|
||||||
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
||||||
|
|
||||||
|
|
||||||
## Dashboard
|
## Dashboard
|
||||||
|
|
||||||
To access the dashboard go to `http://localhost:9001/`
|
To access the dashboard go to `http://127.0.0.1:9001/`
|
||||||
|
|
||||||
##### Preview
|
##### Preview
|
||||||
|
|
||||||
|
|
38
config.go
38
config.go
|
@ -21,32 +21,34 @@ func ReadConfig() Config {
|
||||||
defaultProxyPort := "9000"
|
defaultProxyPort := "9000"
|
||||||
defaultDashboardPort := "9001"
|
defaultDashboardPort := "9001"
|
||||||
defaultMaxCaptures := 16
|
defaultMaxCaptures := 16
|
||||||
|
defaultConfigFile := ".capture.ini"
|
||||||
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")
|
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
||||||
|
configFile := flag.String("config", defaultConfigFile, "Set the configuration file")
|
||||||
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
||||||
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
||||||
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
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("")
|
||||||
|
|
||||||
|
return Config{
|
||||||
|
TargetURL: section.Key("url").MustString(*targetURL),
|
||||||
|
ProxyPort: section.Key("port").MustString(*proxyPort),
|
||||||
|
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
|
||||||
|
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
TargetURL: *targetURL,
|
TargetURL: *targetURL,
|
||||||
ProxyPort: *proxyPort,
|
ProxyPort: *proxyPort,
|
||||||
|
|
6
main.go
6
main.go
|
@ -30,9 +30,9 @@ var dashboardHTML []byte
|
||||||
func main() {
|
func main() {
|
||||||
cfg := ReadConfig()
|
cfg := ReadConfig()
|
||||||
|
|
||||||
fmt.Printf("Target is %s", cfg.TargetURL)
|
fmt.Printf("Target is %s\n", cfg.TargetURL)
|
||||||
fmt.Printf("\nListening on http://localhost:%s", cfg.ProxyPort)
|
fmt.Printf("Listening on http://127.0.0.1:%s\n", cfg.ProxyPort)
|
||||||
fmt.Printf("\nDashboard on http://localhost:%s", cfg.DashboardPort)
|
fmt.Printf("Dashboard on http://127.0.0.1:%s\n", cfg.DashboardPort)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
srv := NewCaptureService(cfg.MaxCaptures)
|
srv := NewCaptureService(cfg.MaxCaptures)
|
||||||
|
|
Loading…
Reference in a new issue