Skip to content

Commit

Permalink
Merge pull request #94 from yanosea/93-add-cors-configuration-for-loc…
Browse files Browse the repository at this point in the history
…al-development-environment
  • Loading branch information
yanosea authored Jan 27, 2025
2 parents f048247 + 5d0617f commit 28659fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/presentation/api/jrp-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Test_main(t *testing.T) {
mockEcho := proxy.NewMockEcho(mockCtrl)
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Group("/api").Return(mockGroup)
mockEcho.EXPECT().Start(":8080")
mockEcho.EXPECT().Get("/swagger/*", gomock.Any())
Expand Down
7 changes: 7 additions & 0 deletions app/presentation/api/jrp-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"errors"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

"github.com/yanosea/jrp/v2/app/infrastructure/database"
Expand Down Expand Up @@ -65,6 +66,12 @@ func (s *server) Init(
}

s.Port = conf.JrpPort
if s.Port == "8080" {
s.Route.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET},
}))
}

if s.ConnectionManager == nil {
s.ConnectionManager = database.NewConnectionManager(sql)
Expand Down
2 changes: 2 additions & 0 deletions app/presentation/api/jrp-server/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func Test_server_Init(t *testing.T) {
mockEcho := proxy.NewMockEcho(mockCtrl)
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Group(gomock.Any()).Return(mockGroup)
mockEcho.EXPECT().Get("/swagger/*", gomock.Any())
mockLogger := proxy.NewMockLogger(mockCtrl)
Expand Down Expand Up @@ -274,6 +275,7 @@ func Test_server_Init(t *testing.T) {
mockEcho := proxy.NewMockEcho(mockCtrl)
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Use(gomock.Any())
mockEcho.EXPECT().Group(gomock.Any()).Return(mockGroup)
mockEcho.EXPECT().Get("/swagger/*", gomock.Any())
mockLogger := proxy.NewMockLogger(mockCtrl)
Expand Down
9 changes: 8 additions & 1 deletion docs/coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@
import (
"errors"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

"github.com/yanosea/jrp/v2/app/infrastructure/database"
Expand Down Expand Up @@ -2325,8 +2326,14 @@
}</span>

<span class="cov8" title="1">s.Port = conf.JrpPort
if s.Port == "8080" </span><span class="cov8" title="1">{
s.Route.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET},
}))
}</span>

if s.ConnectionManager == nil </span><span class="cov8" title="1">{
<span class="cov8" title="1">if s.ConnectionManager == nil </span><span class="cov8" title="1">{
s.ConnectionManager = database.NewConnectionManager(sql)
}</span>

Expand Down

0 comments on commit 28659fe

Please sign in to comment.