Skip to content

Return the host of the call with info #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ It will listen to http and websocket connections on a range of ports from `8990`
### Discover the port
You should make GET request to the `/info` endpoint on the possible ports, until you find a reply:

$ curl http://localhost:8990/info
curl: (7) Failed to connect to localhost port 8990: Connection refused
$ curl http://localhost:8991/info
$ curl http://127.0.0.1:8990/info
curl: (7) Failed to connect to 127.0.0.1 port 8990: Connection refused
$ curl http://127.0.0.1:8991/info

$ curl http://localhost:8992/info
{"http":"http://localhost:8992","https":"https://localhost:8991","version":"1.0.36","ws":"ws://localhost:8992","wss":"wss://localhost:8991"}
$ curl http://127.0.0.1:8992/info
{"http":"http://127.0.0.1:8992","https":"https://127.0.0.1:8991","version":"1.0.36","ws":"ws://127.0.0.1:8992","wss":"wss://127.0.0.1:8991"}

The reply will contain a json with info about the version and the http and https endpoints to use

Expand Down Expand Up @@ -176,7 +176,7 @@ where you should replace /dev/ttyACM0 with the actual port and 9600 with the bau
You will receive a message like:

```json
{
{
"Cmd":"Open",
"Desc":"Got register/open on port.",
"Port":"/dev/ttyACM0",
Expand All @@ -189,7 +189,7 @@ You will receive a message like:
or

```json
{
{
"Cmd":"OpenFail",
"Desc":"Error opening port. Serial port busy",
"Port":"/dev/ttyACM0",
Expand All @@ -204,7 +204,7 @@ You can then close the port with
You will receive a message like:

```json
{
{
"Cmd":"Close",
"Desc":"Got unregister/close on port.",
"Port":"/dev/ttyACM0",
Expand All @@ -216,7 +216,7 @@ or


```json
{
{
"Error":"We could not find the serial port /dev/ttyACM0 that you were trying to close."
}
```
Expand All @@ -238,7 +238,7 @@ with a reply like
You can receive output from the serial port by listening to messages like this:

```json
{
{
"D":"output string\r\n"
}
```
Expand Down
4 changes: 2 additions & 2 deletions certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

var (
host = "localhost"
host = "127.0.0.1"
validFrom = ""
validFor = 365 * 24 * time.Hour * 2 // 2 years
rsaBits = 2048
Expand Down Expand Up @@ -104,7 +104,7 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
Subject: pkix.Name{
Organization: []string{"Arduino LLC US"},
Country: []string{"US"},
CommonName: "localhost",
CommonName: "127.0.0.1",
OrganizationalUnit: []string{"IT"},
},
NotBefore: notBefore,
Expand Down
14 changes: 10 additions & 4 deletions info.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package main

import (
"strings"

"github.com/gin-gonic/gin"
"go.bug.st/serial.v1"
)

func infoHandler(c *gin.Context) {
host := c.Request.Host
parts := strings.Split(host, ":")
host = parts[0]

c.JSON(200, gin.H{
"version": version,
"http": "http://localhost" + port,
"https": "https://localhost" + portSSL,
"ws": "ws://localhost" + port,
"wss": "wss://localhost" + portSSL,
"http": "http://" + host + port,
"https": "https://" + host + portSSL,
"ws": "ws://" + host + port,
"wss": "wss://" + host + portSSL,
})
}

Expand Down
7 changes: 5 additions & 2 deletions trayicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func getConfigs() []ConfigIni {
filepath.Walk(dest, func(path string, f os.FileInfo, _ error) error {
if !f.IsDir() {
if filepath.Ext(path) == ".ini" {
cfg, _ := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, filepath.Join(dest, f.Name()))
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, filepath.Join(dest, f.Name()))
if err != nil {
return err
}
defaultSection, err := cfg.GetSection("")
name := defaultSection.Key("name").String()
if name == "" || err != nil {
Expand Down Expand Up @@ -183,7 +186,7 @@ func setupSysTrayReal() {
for {
<-mDebug.ClickedCh
logAction("log on")
open.Start("http://localhost" + port)
open.Start("http://127.0.0.1" + port)
}
}()

Expand Down