diff --git a/api/api.go b/api/api.go index 70c224c..c3f4351 100644 --- a/api/api.go +++ b/api/api.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "sync" "github.com/medium.rip/api/routes" @@ -16,12 +17,14 @@ import ( ) func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup, engine *html.Engine, fs http.FileSystem) { + // more Fiber options at https://docs.gofiber.io/api/fiber/ app := fiber.New(fiber.Config{ StreamRequestBody: true, ServerHeader: "Katbox", AppName: "Katbox", DisableStartupMessage: true, Views: engine, + Network: "tcp", }) // static file server @@ -30,6 +33,10 @@ func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup, engine *html.Engine Browse: config.Conf.Env == "dev", })) + if config.Conf.Proxy != "" { + log.Printf("Using proxy: %s", config.Conf.Proxy) + } + routes.RegisterRoutes(app) go func(app *fiber.App) { @@ -48,4 +55,4 @@ func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup, engine *html.Engine log.Warn("Server shutdown Failed: ", err) } wg.Done() -} \ No newline at end of file +} diff --git a/frontend/postcss.config.ts b/frontend/postcss.config.cjs similarity index 100% rename from frontend/postcss.config.ts rename to frontend/postcss.config.cjs diff --git a/internal/config/config.go b/internal/config/config.go index 3a338ce..34fe314 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,7 @@ type Config struct { S3Endpoint string `koanf:"S3_ENDPOINT"` Env string `koanf:"ENV"` SecretKey string `koanf:"SECRET_KEY"` + Proxy string `koanf:"PROXY"` } var Conf *Config diff --git a/pkg/client/medium_client.go b/pkg/client/medium_client.go index 117aa84..6f1c13a 100644 --- a/pkg/client/medium_client.go +++ b/pkg/client/medium_client.go @@ -6,6 +6,8 @@ import ( "net/http" "os" "strings" + "net/url" + "crypto/tls" log "github.com/sirupsen/logrus" @@ -30,13 +32,35 @@ func PostData(postId string) (*entities.MediumResponse, error) { } // http client to post data - url := "https://medium.com/_/graphql" + urlreq := "https://medium.com/_/graphql" method := "POST" - + payload := strings.NewReader(fmt.Sprintf("{\"query\":\"query {\\n post(id: \\\"%s\\\") {\\n title\\n createdAt\\n creator {\\n id\\n name\\n }\\n content {\\n bodyModel {\\n paragraphs {\\n name\\n text\\n type\\n href\\n layout\\n markups {\\n title\\n type\\n href\\n userId\\n start\\n end\\n anchorType\\n }\\n iframe {\\n mediaResource {\\n href\\n iframeSrc\\n iframeWidth\\n iframeHeight\\n }\\n }\\n metadata {\\n id\\n originalWidth\\n originalHeight\\n }\\n }\\n }\\n }\\n }\\n }\",\"variables\":{}}", postId)) - client := &http.Client{} - req, err := http.NewRequest(method, url, payload) + //log.Printf("Article ID: %s", postId) + //log.Printf("PAYLOAD: %s", payload) + + var client *http.Client + + if config.Conf.Proxy != "" { + proxyURL, err := url.Parse(config.Conf.Proxy) + if err != nil { + panic(err) + } + client = &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyURL(proxyURL), + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + } + } else { + client = &http.Client{} + } + + req, err := http.NewRequest(method, urlreq, payload) + req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36") if err != nil { log.Printf("Error constructing request %v\n", err) return nil, err