From c38787f46d108b9dfa07187da690682b99b538be Mon Sep 17 00:00:00 2001
From: Leonard Forsberg <leonard.forsberg@vx.se>
Date: Tue, 30 Jan 2024 22:25:52 +0100
Subject: [PATCH] Serve from /docs

---
 app/app.go                 | 12 ++++++------
 public/script.js           |  6 +++---
 views/layouts/main.html    |  2 +-
 views/partials/header.html |  4 ++--
 views/version-select.html  |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/app/app.go b/app/app.go
index 7cfcf28..db60301 100644
--- a/app/app.go
+++ b/app/app.go
@@ -50,18 +50,18 @@ func getCompanyLogo(location string) ([]byte, error) {
 }
 
 func registerHandlers(a *App) {
-	a.fiberApp.Get("/favicon.ico", func(c *fiber.Ctx) error {
+	a.fiberApp.Get("/docs/favicon.ico", func(c *fiber.Ctx) error {
 		return c.Send(a.logo)
 	})
 
 	// Serve static files
-	a.fiberApp.Static("/", staticFilesPath)
+	a.fiberApp.Static("/docs/", staticFilesPath)
 
-	a.fiberApp.Get("/", a.getIndexHandler)
-	a.fiberApp.Get("/:version/:role", a.renderDocHandler)
+	a.fiberApp.Get("/docs/", a.getIndexHandler)
+	a.fiberApp.Get("/docs/:version/:role", a.renderDocHandler)
 
-	a.fiberApp.Get("/versions", a.getVersionsHandler)
-	a.fiberApp.Get("/version/:version/roles", a.getRolesHandler)
+	a.fiberApp.Get("/docs/versions", a.getVersionsHandler)
+	a.fiberApp.Get("/docs/version/:version/roles", a.getRolesHandler)
 }
 
 func validateConfig(cfg *Config) error {
diff --git a/public/script.js b/public/script.js
index 01a47aa..89c1af8 100644
--- a/public/script.js
+++ b/public/script.js
@@ -3,7 +3,7 @@ window.onload = function () {
 };
 
 function setupVersionSelect() {
-    fetch('/versions')
+    fetch('/docs/versions')
         .then(response => response.json())
         .then(versions => {
             var dropdown = document.getElementById('dropdown');
@@ -22,7 +22,7 @@ function setupVersionSelect() {
 
 function handleVersionSelect() {
     const version = document.getElementById('dropdown').value;
-    fetch(`/version/${version}/roles`)
+    fetch(`/docs/version/${version}/roles`)
         .then(response => response.json())
         .then(roles => {
             buttonContainer = document.getElementById('button-container');
@@ -32,7 +32,7 @@ function handleVersionSelect() {
                 button.innerHTML = role;
 
                 button.onclick = function () {
-                    window.location.href = `/${version}/${role}`;
+                    window.location.href = `/docs/${version}/${role}`;
                 };
 
                 buttonContainer.appendChild(button);
diff --git a/views/layouts/main.html b/views/layouts/main.html
index 64461e4..4d721ac 100644
--- a/views/layouts/main.html
+++ b/views/layouts/main.html
@@ -5,7 +5,7 @@
     <title>{{ .CompanyName }} Api</title>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <link rel="stylesheet" href="/style.css">
+    <link rel="stylesheet" href="/docs/style.css">
 </head>
 
 <body>
diff --git a/views/partials/header.html b/views/partials/header.html
index 9f907f2..651cec2 100644
--- a/views/partials/header.html
+++ b/views/partials/header.html
@@ -1,8 +1,8 @@
 <header>
-    <a href="/">
+    <a href="/docs/">
         <img src="{{ .CompanyLogo }}" alt="company logo">
     </a>
-    <a href="/">
+    <a href="/docs/">
         <h1>{{ .CompanyName }}</h1>
     </a>
 </header>
\ No newline at end of file
diff --git a/views/version-select.html b/views/version-select.html
index d9a26a6..1917730 100644
--- a/views/version-select.html
+++ b/views/version-select.html
@@ -12,4 +12,4 @@ <h2>Select documentation:</h2>
         </div>
     </div>
 </div>
-<script src="/script.js"></script>
\ No newline at end of file
+<script src="/docs/script.js"></script>
\ No newline at end of file