feat: add cors to fiber app

This commit is contained in:
AmirMahdi Qiasvand 2025-09-15 20:14:00 +03:30
parent c27e3945d5
commit e3d37a8e4d
5 changed files with 15 additions and 150 deletions

View File

@ -119,59 +119,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/send-otp": { "/auth/kyc": {
"post": {
"description": "Send OTP code to the provided phone number",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Send OTP code",
"parameters": [
{
"description": "OTP Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OTPProviderReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.OTPProviderResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/auth/verify-kyc": {
"post": { "post": {
"description": "Verify user KYC with national ID and birth date", "description": "Verify user KYC with national ID and birth date",
"consumes": [ "consumes": [
@ -223,7 +171,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/verify-otp": { "/auth/otp": {
"post": { "post": {
"description": "Verify the provided OTP code for the phone number", "description": "Verify the provided OTP code for the phone number",
"consumes": [ "consumes": [

View File

@ -108,59 +108,7 @@
} }
} }
}, },
"/auth/send-otp": { "/auth/kyc": {
"post": {
"description": "Send OTP code to the provided phone number",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Send OTP code",
"parameters": [
{
"description": "OTP Request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OTPProviderReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.OTPProviderResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/auth/verify-kyc": {
"post": { "post": {
"description": "Verify user KYC with national ID and birth date", "description": "Verify user KYC with national ID and birth date",
"consumes": [ "consumes": [
@ -212,7 +160,7 @@
} }
} }
}, },
"/auth/verify-otp": { "/auth/otp": {
"post": { "post": {
"description": "Verify the provided OTP code for the phone number", "description": "Verify the provided OTP code for the phone number",
"consumes": [ "consumes": [

View File

@ -148,41 +148,7 @@ paths:
summary: Generate authentication challenge summary: Generate authentication challenge
tags: tags:
- auth - auth
/auth/send-otp: /auth/kyc:
post:
consumes:
- application/json
description: Send OTP code to the provided phone number
parameters:
- description: OTP Request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.OTPProviderReq'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.OTPProviderResponse'
"400":
description: Bad Request
schema:
additionalProperties:
type: string
type: object
"500":
description: Internal Server Error
schema:
additionalProperties:
type: string
type: object
summary: Send OTP code
tags:
- auth
/auth/verify-kyc:
post: post:
consumes: consumes:
- application/json - application/json
@ -216,7 +182,7 @@ paths:
summary: Verify user KYC summary: Verify user KYC
tags: tags:
- auth - auth
/auth/verify-otp: /auth/otp:
post: post:
consumes: consumes:
- application/json - application/json

View File

@ -101,7 +101,7 @@ func (h *AuthHandler) Authenticate(c *fiber.Ctx) error {
// @Success 200 {object} dto.OTPProviderResponse // @Success 200 {object} dto.OTPProviderResponse
// @Failure 400 {object} map[string]string // @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string // @Failure 500 {object} map[string]string
// @Router /auth/send-otp [post] // @Router /auth/otp [post]
func (h *AuthHandler) SendOTP(c *fiber.Ctx) error { func (h *AuthHandler) SendOTP(c *fiber.Ctx) error {
var req dto.OTPProviderReq var req dto.OTPProviderReq
if err := c.BodyParser(&req); err != nil { if err := c.BodyParser(&req); err != nil {
@ -132,7 +132,7 @@ func (h *AuthHandler) SendOTP(c *fiber.Ctx) error {
// @Success 200 {object} dto.OTPVerifyResponse // @Success 200 {object} dto.OTPVerifyResponse
// @Failure 400 {object} map[string]string // @Failure 400 {object} map[string]string
// @Failure 401 {object} map[string]string // @Failure 401 {object} map[string]string
// @Router /auth/verify-otp [post] // @Router /auth/otp [post]
func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error { func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error {
var req dto.OTPVerifyRequest var req dto.OTPVerifyRequest
if err := c.BodyParser(&req); err != nil { if err := c.BodyParser(&req); err != nil {
@ -163,7 +163,7 @@ func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error {
// @Success 200 {object} dto.KYCVerifyResponse // @Success 200 {object} dto.KYCVerifyResponse
// @Failure 400 {object} map[string]string // @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string // @Failure 500 {object} map[string]string
// @Router /auth/verify-kyc [post] // @Router /auth/kyc [post]
func (h *AuthHandler) VerifyKYC(c *fiber.Ctx) error { func (h *AuthHandler) VerifyKYC(c *fiber.Ctx) error {
var req dto.KYCVerifyRequest var req dto.KYCVerifyRequest
if err := c.BodyParser(&req); err != nil { if err := c.BodyParser(&req); err != nil {

View File

@ -11,12 +11,15 @@ import (
"github.com/gofiber/adaptor/v2" "github.com/gofiber/adaptor/v2"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
httpSwagger "github.com/swaggo/http-swagger" httpSwagger "github.com/swaggo/http-swagger"
) )
func Run(cfg config.Server, app *app.AppContainer) { func Run(cfg config.Server, app *app.AppContainer) {
fiberApp := fiber.New() fiberApp := fiber.New()
fiberApp.Use(cors.New())
// Serve static files (HTML, CSS, JS) // Serve static files (HTML, CSS, JS)
fiberApp.Static("/", "./static") fiberApp.Static("/", "./static")
@ -47,8 +50,8 @@ func registerPublicRoutes(router fiber.Router, app *app.AppContainer) {
// Register auth routes // Register auth routes
authgroup.Post("/challenge", authHandler.GenerateChallenge) authgroup.Post("/challenge", authHandler.GenerateChallenge)
authgroup.Post("/authenticate", authHandler.Authenticate) authgroup.Post("/authenticate", authHandler.Authenticate)
authgroup.Post("/send-otp", authHandler.SendOTP) authgroup.Post("/otp", authHandler.SendOTP)
authgroup.Post("/verify-otp", authHandler.VerifyOTP) authgroup.Post("/verify", authHandler.VerifyOTP)
// add JWT middleware for KYC // add JWT middleware for KYC
authgroup.Post("/verify-kyc", authHandler.VerifyKYC) authgroup.Post("/kyc", authHandler.VerifyKYC)
} }