-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (31 loc) · 834 Bytes
/
main.go
File metadata and controls
39 lines (31 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"time"
"myapp/handlers"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
// Auth
r.POST("/login", handlers.Login)
r.POST("/logout", handlers.Logout)
// Posts CRUD (JWT 보호)
posts := r.Group("/posts")
posts.Use(handlers.AuthMiddleware())
{
posts.POST("", handlers.CreatePost)
posts.GET("", handlers.GetPosts)
posts.GET("/:id", handlers.GetPostByID)
posts.PUT("/:id", handlers.UpdatePost)
posts.DELETE("/:id", handlers.DeletePost)
}
r.Run(":8080")
}