build docker image
This commit is contained in:
78
cmd/main.go
78
cmd/main.go
@@ -1,73 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"paywall-ladder/handlers"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"strconv"
|
||||
|
||||
"github.com/elazarl/goproxy"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
if os.Getenv("PORT_PROXY") == "" {
|
||||
os.Setenv("PORT_PROXY", "3000")
|
||||
}
|
||||
if os.Getenv("HTTP_PROXY") == "" {
|
||||
os.Setenv("HTTP_PROXY", "http://127.0.0.1:"+os.Getenv("PORT_PROXY"))
|
||||
}
|
||||
|
||||
proxyForkID := uintptr(0)
|
||||
if runtime.GOOS == "darwin" {
|
||||
_, proxyForkID, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
|
||||
} else if runtime.GOOS == "linux" {
|
||||
proxyForkID, _, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
|
||||
}
|
||||
|
||||
fmt.Println("Proxy fork id", proxyForkID)
|
||||
|
||||
if proxyForkID == 0 {
|
||||
|
||||
app := fiber.New(
|
||||
fiber.Config{
|
||||
Prefork: false,
|
||||
},
|
||||
)
|
||||
|
||||
//app.Static("/", "./public")
|
||||
app.Get("/", handlers.Form)
|
||||
|
||||
app.Get("/proxy/*", handlers.FetchSite)
|
||||
app.Get("debug/*", handlers.Debug)
|
||||
app.Get("debug2/*", handlers.Debug2)
|
||||
app.Get("/*", handlers.ProxySite)
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if os.Getenv("PORT") == "" {
|
||||
port = "2000"
|
||||
}
|
||||
app.Listen(":" + port)
|
||||
} else {
|
||||
proxy := goproxy.NewProxyHttpServer()
|
||||
proxy.Verbose = true
|
||||
proxy.OnRequest().DoFunc(
|
||||
func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
|
||||
req.Header.Set("X-Forwarded-For", "66.249.66.1")
|
||||
return req, nil
|
||||
})
|
||||
|
||||
proxyport := os.Getenv("PORT_PROXY")
|
||||
if os.Getenv("PORT_PROXY") == "" {
|
||||
proxyport = "3000"
|
||||
}
|
||||
log.Println("Proxy listening on port " + proxyport)
|
||||
log.Fatal(http.ListenAndServe(":"+proxyport, proxy))
|
||||
prefork, _ := strconv.ParseBool(os.Getenv("PREFORK"))
|
||||
app := fiber.New(
|
||||
fiber.Config{
|
||||
Prefork: prefork,
|
||||
},
|
||||
)
|
||||
|
||||
//app.Static("/", "./public")
|
||||
app.Get("/", handlers.Form)
|
||||
|
||||
app.Get("/proxy/*", handlers.FetchSite)
|
||||
app.Get("debug/*", handlers.Debug)
|
||||
app.Get("debug2/*", handlers.Debug2)
|
||||
app.Get("/*", handlers.ProxySite)
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if os.Getenv("PORT") == "" {
|
||||
port = "2000"
|
||||
}
|
||||
log.Fatal(app.Listen(":" + port))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user