feat(oauth): add twitter oauth support

This commit is contained in:
Gustavo "Guz" L. de Mello
2024-06-27 19:53:09 -03:00
parent 1bc25628c3
commit 37fd862590
10 changed files with 312 additions and 36 deletions

34
main.go
View File

@@ -5,11 +5,9 @@ import (
"fmt"
"log"
"net/http"
"slices"
"strings"
"extrovert/config"
"extrovert/internals"
"extrovert/pages"
)
var logger = log.Default()
@@ -28,41 +26,13 @@ func main() {
mux := http.NewServeMux()
config.APIROUTES(mux)
for _, route := range config.ROUTES {
path := "/" + strings.TrimSuffix(route.Path, ".html")
if path == "/index" {
continue
}
logger.Printf("Registering page route. page=%s route=%s", route.Path, path)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
err := route.Component.Render(r.Context(), w)
if err != nil {
logger.Fatalf("Unable to render route %s due to %s", route.Path, err)
}
})
}
pages.RegisterAllRoutes(pages.ROUTES, mux)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
logger.Printf("Handling file server request. path=%s", r.URL.Path)
http.FileServer(http.Dir(*staticDir)).ServeHTTP(w, r)
return
}
w.Header().Add("Content-Type", "text/html")
index := slices.IndexFunc(config.ROUTES, func(route internals.Page) bool {
return route.Path == "index.html"
})
indexPage := config.ROUTES[index]
err := indexPage.Component.Render(r.Context(), w)
if err != nil {
log.Fatalf("Unable to render index page due to %s", err)
}
})
logger.Printf("Running server at port: %v", *port)