Skip to content

Commit a6d5c92

Browse files
authored
feat(cors): Allow cross origin verification requests (#26)
1 parent ccf9b5a commit a6d5c92

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

.github/workflows/format.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
- uses: actions/setup-go@v4
1212
with:
1313
go-version-file: "go.mod"
14-
- uses: golangci/golangci-lint-action@v3
14+
- uses: golangci/golangci-lint-action@v8
15+
with:
16+
version: v2.4.0
1517
tidy:
1618
name: Tidy go modules
1719
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
handles-server
2+
bin/

Taskfile.dist.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ tasks:
2727
- golang-ci
2828
cmds:
2929
- go fmt .
30-
- golangci-lint run
30+
- ./bin/golangci-lint run
3131
- go mod tidy
3232

3333
golang-ci:
3434
status:
35-
- golangci-lint version && exit 0
35+
- ./bin/golangci-lint version && exit 0
3636
cmds:
3737
- >
38-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |
39-
sh -s -- -b $(go env GOPATH)/bin v1.53.3
38+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |
39+
sh -s v2.4.0

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"reflect"
88

9-
"github.com/caarlos0/env/v11"
9+
env "github.com/caarlos0/env/v11"
1010
"github.com/jackc/pgx/v5/pgxpool"
1111
"github.com/jackc/pgx/v5/tracelog"
1212
pgxslog "github.com/mcosta74/pgx-slog"

main_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,15 @@ func TestUnknownHandleRedirectsToDestination(t *testing.T) {
143143
assert.Equal(t, "https://example.com/register?handle=carol.example.com", url.String())
144144

145145
}
146+
147+
func TestDidEndpointAllowsCrossOriginRequests(t *testing.T) {
148+
router, _ := NewTestEnvironment()
149+
150+
res := httptest.NewRecorder()
151+
req, _ := http.NewRequest("GET", "https://alice.example.com/.well-known/atproto-did", nil)
152+
router.ServeHTTP(res, req)
153+
154+
assert.Equal(t, http.StatusOK, res.Code)
155+
assert.Equal(t, "did:plc:example001", res.Body.String())
156+
assert.Equal(t, "*", res.Header().Get("Access-Control-Allow-Origin"))
157+
}

pg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"fmt"
77

8-
"github.com/jackc/pgx/v5"
8+
pgx "github.com/jackc/pgx/v5"
99
"github.com/jackc/pgx/v5/pgxpool"
1010
)
1111

router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func VerifyHandle(c *gin.Context) {
100100
return
101101
}
102102

103+
c.Header("Access-Control-Allow-Origin", "*")
103104
c.String(http.StatusOK, string(result.DecentralizedID))
104105
}
105106

0 commit comments

Comments
 (0)