Skip to content

Commit 33aa06c

Browse files
committed
feat: first working commit
0 parents  commit 33aa06c

7 files changed

Lines changed: 206 additions & 0 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT LICENSE
2+
3+
Copyright (c) 2025 Daniel Vergara
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# jumble-proxy-server
2+
3+
__This application is a proxy server used by the Jumble Nostr client as a workaround to fix CORS erros,so that the client can show the URL preview from links' Open Graph data.__
4+
5+
## Usage
6+
```sh
7+
jumble-proxy-server -a https://jumble.social -p 8080
8+
```
9+
10+
```sh
11+
curl -X GET http://localhost:8080/sites/https:/www.youtube.com/watch\?v\=i-OZcpNSzg0
12+
```

cmd/root.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright © 2025 Daniel Vergara daniel.omar.vergara@gmail.com
3+
*/
4+
package cmd
5+
6+
import (
7+
"os"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// rootCmd represents the base command when called without any subcommands
13+
var rootCmd = &cobra.Command{
14+
Use: "jumble-proxy-server",
15+
Short: "Golang Backend Server as a Proxy to overcome CORS errors for the Jumble Nostr client",
16+
Long: `This application is a proxy server used by the Jumble Nostr client as a workaround to fix CORS erros,
17+
so that the client can show the URL preview from links' Open Graph data.`,
18+
// Uncomment the following line if your bare application
19+
// has an action associated with it:
20+
// Run: func(cmd *cobra.Command, args []string) { },
21+
}
22+
23+
// Execute adds all child commands to the root command and sets flags appropriately.
24+
// This is called by main.main(). It only needs to happen once to the rootCmd.
25+
func Execute() {
26+
err := rootCmd.Execute()
27+
if err != nil {
28+
os.Exit(1)
29+
}
30+
}
31+
32+
func init() {
33+
// Here you will define your flags and configuration settings.
34+
// Cobra supports persistent flags, which, if defined here,
35+
// will be global for your application.
36+
37+
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jumble-proxy-server.yaml)")
38+
39+
// Cobra also supports local flags, which will only run
40+
// when this action is called directly.
41+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
42+
}

cmd/server.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"io"
9+
"log"
10+
"net/http"
11+
"os"
12+
13+
"github.com/spf13/cobra"
14+
)
15+
16+
var (
17+
port string
18+
allowedOrigin string
19+
)
20+
21+
// serverCmd represents the server command
22+
var serverCmd = &cobra.Command{
23+
Use: "server",
24+
Short: "Golang Backend Server as a Proxy to overcome CORS errors for the Jumble Nostr client",
25+
Long: `This application is a proxy server used by the Jumble Nostr client as a workaround to fix CORS erros,
26+
so that the client can show the URL preview from links' Open Graph data.`,
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
if port == "" {
29+
port = "8000"
30+
}
31+
32+
http.HandleFunc("GET /sites/{site}", proxyHandler)
33+
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
34+
fmt.Fprintf(os.Stderr, "%s\n", err)
35+
os.Exit(1)
36+
}
37+
38+
log.Printf("server listening on port %s\n", port)
39+
40+
return nil
41+
},
42+
}
43+
44+
func proxyHandler(w http.ResponseWriter, r *http.Request) {
45+
if allowedOrigin == "" {
46+
allowedOrigin = "*"
47+
}
48+
49+
w.Header().Set("Access-Control-Allow-Origin", allowedOrigin)
50+
w.Header().Set("Access-Control-Allow-Methods", "GET")
51+
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
52+
53+
site := r.PathValue("site")
54+
55+
// Send request to the target site.
56+
req, err := http.NewRequest(r.Method, site, r.Body)
57+
if err != nil {
58+
http.Error(w, "Failed to create request", http.StatusInternalServerError)
59+
return
60+
}
61+
62+
// Copy headers from original request.
63+
for header, values := range r.Header {
64+
for _, value := range values {
65+
req.Header.Add(header, value)
66+
}
67+
}
68+
69+
// Perform the proxy request.
70+
client := &http.Client{}
71+
resp, err := client.Do(req)
72+
if err != nil {
73+
fmt.Printf("Proxy request failed %v", err)
74+
http.Error(w, "Proxy request failed", http.StatusBadGateway)
75+
return
76+
}
77+
78+
defer resp.Body.Close()
79+
80+
// Copy the response headers.
81+
for header, values := range resp.Header {
82+
for _, value := range values {
83+
w.Header().Add(header, value)
84+
}
85+
}
86+
87+
// Set the status code and write the response body.
88+
w.WriteHeader(resp.StatusCode)
89+
body, _ := io.ReadAll(resp.Body)
90+
w.Write(body)
91+
}
92+
93+
func init() {
94+
rootCmd.AddCommand(serverCmd)
95+
96+
serverCmd.Flags().
97+
StringVarP(&allowedOrigin, "allowed-origin", "a", "", "Restrict access to a specific allowed domain")
98+
serverCmd.Flags().
99+
StringVarP(&port, "port", "p", "", "Server Port")
100+
}

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/danvergara/jumble-proxy-server
2+
3+
go 1.24.2
4+
5+
require github.com/spf13/cobra v1.9.1
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.6 // indirect
10+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
7+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
8+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package main
6+
7+
import "github.com/danvergara/jumble-proxy-server/cmd"
8+
9+
func main() {
10+
cmd.Execute()
11+
}

0 commit comments

Comments
 (0)