From 5376d04adfb3a5fc9f543fa6ad11c58d12db720c Mon Sep 17 00:00:00 2001
From: Ophestra Umiker <cat@ophivana.moe>
Date: Wed, 16 Oct 2024 21:45:12 +0900
Subject: [PATCH] feat(api)!: clean up API paths

All API endpoints are moved under /api.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
---
 app.go      | 7 ++-----
 captcha.go  | 4 ++--
 register.go | 4 ++--
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/app.go b/app.go
index 2f2e8b7..08cd160 100644
--- a/app.go
+++ b/app.go
@@ -54,11 +54,8 @@ func serve(sig chan os.Signal, db *leveldb.DB) error {
 			confEnv[hCaptchaSiteKey][0], confEnv[hCaptchaSecretKey][0])
 	}
 
-	// /register
-	routeRegister(app, db, captcha)
-
-	// /hcaptcha-site-key
-	routeHCaptchaSiteKey(app, !hCaptchaEnable, conf[hCaptchaSiteKey])
+	routeHCaptchaSiteKey(app, "/api", !hCaptchaEnable, conf[hCaptchaSiteKey])
+	routeRegister(app, "/api/register", db, captcha)
 
 	// graceful shutdown
 	go func() {
diff --git a/captcha.go b/captcha.go
index f2d517d..d8e0612 100644
--- a/captcha.go
+++ b/captcha.go
@@ -12,7 +12,7 @@ type respHSiteKey struct {
 // Route to expose hCaptcha site key.
 // Returns a constant pre-generated response
 // to avoid unnecessary allocations or serialisations
-func routeHCaptchaSiteKey(app *fiber.App, stub bool, siteKey string) {
+func routeHCaptchaSiteKey(app *fiber.App, p string, stub bool, siteKey string) {
 	var resp string
 	if stub {
 		resp = mustConstResp(newMessage(false, "hCaptcha is not enabled on this instance."))
@@ -20,7 +20,7 @@ func routeHCaptchaSiteKey(app *fiber.App, stub bool, siteKey string) {
 		resp = mustConstResp(respHSiteKey{true, siteKey})
 	}
 
-	app.Get("/captcha", func(c fiber.Ctx) error {
+	app.Get(p, func(c fiber.Ctx) error {
 		c.Set("Content-Type", "application/json; charset=utf-8")
 		return c.SendString(resp)
 	})
diff --git a/register.go b/register.go
index acf1525..a27fb24 100644
--- a/register.go
+++ b/register.go
@@ -15,8 +15,8 @@ type registration struct {
 }
 
 // Waitlist registration route
-func routeRegister(app *fiber.App, db *leveldb.DB, captcha fiber.Handler) {
-	app.Post("/register", func(c fiber.Ctx) error {
+func routeRegister(app *fiber.App, p string, db *leveldb.DB, captcha fiber.Handler) {
+	app.Post(p, func(c fiber.Ctx) error {
 		req := new(registration)
 
 		// Parse and validate the request
-- 
GitLab