mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-25 15:08:35 -06:00
changed hardcoded url to use environment variables
This commit is contained in:
parent
84e7a0a230
commit
02f320379e
2 changed files with 54 additions and 8 deletions
22
README.md
22
README.md
|
@ -3,3 +3,25 @@
|
||||||
PrivTracker allows to share torrent files just with your friends, nobody else.
|
PrivTracker allows to share torrent files just with your friends, nobody else.
|
||||||
Unlike public trackers, it shares peers only within a group which is using the same Announce URL.
|
Unlike public trackers, it shares peers only within a group which is using the same Announce URL.
|
||||||
It really works like a private tracker, but can be generated with one click of a button.
|
It really works like a private tracker, but can be generated with one click of a button.
|
||||||
|
|
||||||
|
---
|
||||||
|
### Build
|
||||||
|
```bash
|
||||||
|
# Clone this repository.
|
||||||
|
$ git clone https://github.com/meehow/privtracker.git
|
||||||
|
|
||||||
|
# cd into the directory
|
||||||
|
$ cd privtracker
|
||||||
|
|
||||||
|
# Run go build
|
||||||
|
$ go build
|
||||||
|
```
|
||||||
|
### Usage
|
||||||
|
```bash
|
||||||
|
# Runs on port 1337 and redirects to privtracker.com by default.
|
||||||
|
$ ./privtracker
|
||||||
|
```
|
||||||
|
```bash
|
||||||
|
# Export PORT and DOMAIN variables to use custom values.
|
||||||
|
$ export PORT=12345 DOMAIN=customprivtracker.com; ./privtracker
|
||||||
|
```
|
40
main.go
40
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -16,6 +17,8 @@ import (
|
||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var envConfig = getEnvConfig()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go Cleanup()
|
go Cleanup()
|
||||||
config := fiber.Config{
|
config := fiber.Config{
|
||||||
|
@ -30,6 +33,7 @@ func main() {
|
||||||
config.TrustedProxies = []string{"127.0.0.1"}
|
config.TrustedProxies = []string{"127.0.0.1"}
|
||||||
config.ProxyHeader = fiber.HeaderXForwardedFor
|
config.ProxyHeader = fiber.HeaderXForwardedFor
|
||||||
}
|
}
|
||||||
|
|
||||||
app := fiber.New(config)
|
app := fiber.New(config)
|
||||||
app.Use(recover.New())
|
app.Use(recover.New())
|
||||||
// app.Use(pprof.New())
|
// app.Use(pprof.New())
|
||||||
|
@ -50,14 +54,34 @@ func main() {
|
||||||
split := strings.Split(domains, ",")
|
split := strings.Split(domains, ",")
|
||||||
log.Fatal(app.Listener(myListener(split...)))
|
log.Fatal(app.Listener(myListener(split...)))
|
||||||
} else {
|
} else {
|
||||||
port := os.Getenv("PORT")
|
log.Fatal(app.Listen(":" + envConfig.port))
|
||||||
if port == "" {
|
|
||||||
port = "1337"
|
|
||||||
}
|
|
||||||
log.Fatal(app.Listen(":" + port))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EnvConfig struct {
|
||||||
|
domain string
|
||||||
|
port string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvConfig() EnvConfig {
|
||||||
|
|
||||||
|
config := EnvConfig{
|
||||||
|
domain: "privtracker.com",
|
||||||
|
port: "1337",
|
||||||
|
}
|
||||||
|
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
domain := os.Getenv("DOMAIN")
|
||||||
|
if domain != "" {
|
||||||
|
config.domain = domain
|
||||||
|
}
|
||||||
|
if port != "" {
|
||||||
|
config.port = port
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
func myListener(domains ...string) net.Listener {
|
func myListener(domains ...string) net.Listener {
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -98,7 +122,7 @@ func redirect80(config fiber.Config) {
|
||||||
config.DisableStartupMessage = true
|
config.DisableStartupMessage = true
|
||||||
app := fiber.New(config)
|
app := fiber.New(config)
|
||||||
app.Use(func(c *fiber.Ctx) error {
|
app.Use(func(c *fiber.Ctx) error {
|
||||||
return c.Redirect("https://privtracker.com/", fiber.StatusMovedPermanently)
|
return c.Redirect(fmt.Sprintf("https://%s/", envConfig.domain), fiber.StatusMovedPermanently)
|
||||||
})
|
})
|
||||||
log.Print(app.Listen(":80"))
|
log.Print(app.Listen(":80"))
|
||||||
}
|
}
|
||||||
|
@ -115,8 +139,8 @@ func hsts(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func docs(c *fiber.Ctx) error {
|
func docs(c *fiber.Ctx) error {
|
||||||
if c.Hostname() != "privtracker.com" {
|
if c.Hostname() != envConfig.domain {
|
||||||
return c.Redirect("https://privtracker.com/", fiber.StatusMovedPermanently)
|
return c.Redirect(fmt.Sprintf("https://%s/", envConfig.domain), fiber.StatusMovedPermanently)
|
||||||
}
|
}
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue