-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api/domain): add GET
/conf/domain
endpoint
- Loading branch information
Showing
7 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handler | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/ArtalkJS/Artalk/internal/core" | ||
"github.com/ArtalkJS/Artalk/server/common" | ||
"github.com/ArtalkJS/Artalk/server/middleware" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ResponseConfDomain struct { | ||
Origin string `json:"origin"` // The origin of the domain | ||
IsTrusted bool `json:"is_trusted"` // Is the domain trusted | ||
} | ||
|
||
// @Id GetDomain | ||
// @Summary Get Domain Info | ||
// @Description Get Domain Info | ||
// @Tags System | ||
// @Produce json | ||
// @Param url query string false "Domain URL" | ||
// @Success 200 {object} ResponseConfDomain | ||
// @Router /conf/domain [get] | ||
func ConfDomain(app *core.App, router fiber.Router) { | ||
router.Get("/conf/domain", func(c *fiber.Ctx) error { | ||
domainURL := c.Query("url") | ||
if domainURL == "" { | ||
domainURL = c.Get("Origin") | ||
} | ||
u, err := url.Parse(domainURL) | ||
if err != nil { | ||
return common.RespError(c, 400, "Invalid URL") | ||
} | ||
origin := u.Scheme + "://" + u.Host | ||
isTrusted := middleware.CheckOriginTrusted(app, origin) | ||
return common.RespData(c, ResponseConfDomain{ | ||
IsTrusted: isTrusted, | ||
Origin: origin, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.