Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #66 from yoshihiro-shu/yoshi/update/cors-middleware
Browse files Browse the repository at this point in the history
Yoshi/update/cors middleware
  • Loading branch information
yoshihiro-shu authored Oct 21, 2023
2 parents ff93b94 + 11b62c2 commit e5e62d3
Show file tree
Hide file tree
Showing 26 changed files with 1,875 additions and 14 deletions.
22 changes: 22 additions & 0 deletions .editconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[{*.go,Makefile,.gitmodules,go.mod,go.sum}]
indent_style = tab

[*.md]
indent_style = tab
trim_trailing_whitespace = false

[*.{yml,yaml,json}]
indent_style = space
indent_size = 2

[*.{js,jsx,ts,tsx,css,less,sass,scss,vue,py}]
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
golang 1.20
rust 1.73.0
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
start:
sh ./scripts/docker-start.sh

stop:
sh ./scripts/docker-stop.sh

init-doc:
swag init --dir backend/cmd
2 changes: 1 addition & 1 deletion backend/.tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.20
golang 1.21rc3
1 change: 1 addition & 0 deletions backend/domain/model/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "time"
type Category struct {
Id int `gorm:"primaryKey;" json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
ParentId int `json:"parentId"`
CreatedAt time.Time `json:"createdAt"`
Expand Down
1 change: 1 addition & 0 deletions backend/domain/model/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "time"
type Tag struct {
Id int `gorm:"primaryKey;" json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
}
Expand Down
1 change: 1 addition & 0 deletions backend/interfaces/api/middlewares/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func Cors(c config.Frontend) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Max-Age", "3600")
w.Header().Set("Access-Control-Allow-Origin", c.Domain)
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Content-Type", "application/json;charset=utf-8")
Expand Down
9 changes: 4 additions & 5 deletions backend/interfaces/api/middlewares/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ const (

func SetterCsrfToken(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// フロント側のブラウザにクッキーがセットされるようにする
w.Header().Set("Access-Control-Allow-Credentials", "true")
switch r.Method {
case http.MethodOptions:
w.Header().Set("Access-Control-Allow-Headers", headerName)
w.Header().Set("Access-Control-Allow-Credentials", "true")
// w.Header().Set("Access-Control-Allow-Headers", headerName)
w.Header().Set("Access-Control-Request-Headers", headerName)
case http.MethodGet:
// X-CSRF-Tokenをフロント側で受け取れるようにする
w.Header().Set("Access-Control-Expose-Headers", headerName)
// フロント側のブラウザにクッキーがセットされるようにする
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set(headerName, csrf.Token(r))
case http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete:
// X-CSRF-Tokenをフロント側で受け取れるようにする
w.Header().Set("Access-Control-Expose-Headers", headerName)
w.Header().Set("Access-Control-Allow-Credentials", "true")
}

next.ServeHTTP(w, r)
Expand Down
6 changes: 6 additions & 0 deletions batch/qiita/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=password
DB_NAME=postgres
DB_SSL=disable
1 change: 1 addition & 0 deletions batch/qiita/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
1 change: 1 addition & 0 deletions batch/qiita/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Loading

0 comments on commit e5e62d3

Please sign in to comment.