Skip to content

Commit

Permalink
fix: include public facing hostname in QR code URL
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjago committed Oct 31, 2021
1 parent 4c62468 commit cb2790a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.4.1 (2021-10-31)

### Bug fixes
- Provide a way to specify the host URL in the QR code (don't know how I missed
this!)

## 0.4.0 (2021-09-21)

### New features
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ const (
staticDir = "./public"
driver = "sqlite3"
dataSource = "sqlite_db"
// This is only for generating the QR code from a URL since when it's
// running behind nginx, for example, it doesn't know what the outside
// facing hostname is unless we tell it. A real setup might look like:
// this program running on localhost:8090, but nginx accepts requests at
// https://file.com, in which case the below value would be https://file.com
publicHost = "https://goupfile.com"
)
```

These probably should be moved to environment variables.

### Proxying though nginx

It's common to proxy requests through a server like nginx. This allows you to
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func createURL(id, action string) string {

func createQR(url string) []byte {
var png []byte
qr, err := qrcode.New(url, qrcode.Medium)
qr, err := qrcode.New(publicHost+url, qrcode.Medium)
if err != nil {
log.Println("Unable to create QR code: ", err)
}
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const (
staticDir = "./public"
driver = "sqlite3"
dataSource = "sqlite_db"
// This is only for generating the QR code from a URL since when it's
// running behind nginx, for example, it doesn't know what the outside
// facing hostname is unless we tell it. A real setup might look like:
// this program running on localhost:8090, but nginx accepts requests at
// https://file.com, in which case the below value would be https://file.com
publicHost = "https://goupfile.com"
)

const schema = `
Expand Down

0 comments on commit cb2790a

Please sign in to comment.