upgrade assets to new frontend

This commit is contained in:
gempir 2020-11-08 16:43:30 +01:00
parent ed7c5023df
commit bba5f85526
6 changed files with 103 additions and 37 deletions

View file

@ -9,7 +9,7 @@ import (
"github.com/shurcooL/vfsgen"
)
var assets http.FileSystem = http.Dir("web/public")
var assets http.FileSystem = http.Dir("web/build")
func main() {
err := vfsgen.Generate(assets, vfsgen.Options{

File diff suppressed because one or more lines are too long

View file

@ -30,7 +30,6 @@ type Server struct {
fileLogger *filelog.Logger
helixClient *helix.Client
channels []string
assets []string
assetHandler http.Handler
}
@ -44,7 +43,6 @@ func NewServer(cfg *config.Config, bot *bot.Bot, fileLogger *filelog.Logger, hel
fileLogger: fileLogger,
helixClient: helixClient,
channels: channels,
assets: []string{"/", "/favicon.ico", "/robots.txt"},
assetHandler: http.FileServer(assets),
}
}
@ -115,11 +113,6 @@ func (s *Server) Init() {
func (s *Server) route(w http.ResponseWriter, r *http.Request) {
url := r.URL.EscapedPath()
if contains(s.assets, url) || strings.HasPrefix(url, "/bundle") {
s.assetHandler.ServeHTTP(w, r)
return
}
query := s.fillUserids(w, r)
if url == "/list" {
@ -148,7 +141,12 @@ func (s *Server) route(w http.ResponseWriter, r *http.Request) {
return
}
s.routeLogs(w, r)
routedLogs := s.routeLogs(w, r)
if !routedLogs {
s.assetHandler.ServeHTTP(w, r)
return
}
}
func (s *Server) fillUserids(w http.ResponseWriter, r *http.Request) url.Values {
@ -177,16 +175,14 @@ func (s *Server) fillUserids(w http.ResponseWriter, r *http.Request) url.Values
return query
}
func (s *Server) routeLogs(w http.ResponseWriter, r *http.Request) {
func (s *Server) routeLogs(w http.ResponseWriter, r *http.Request) bool {
request, err := s.newLogRequestFromURL(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
return false
}
if request.redirectPath != "" {
http.Redirect(w, r, request.redirectPath, http.StatusFound)
return
return false
}
var logs *chatLog
@ -210,7 +206,7 @@ func (s *Server) routeLogs(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Error(err)
http.Error(w, "could not load logs", http.StatusInternalServerError)
return
return true
}
// Disable content type sniffing for log output
@ -218,20 +214,20 @@ func (s *Server) routeLogs(w http.ResponseWriter, r *http.Request) {
if request.responseType == responseTypeJSON {
writeJSON(logs, http.StatusOK, w, r)
return
return true
}
if request.responseType == responseTypeRaw {
writeRaw(logs, http.StatusOK, w, r)
return
return true
}
if request.responseType == responseTypeText {
writeText(logs, http.StatusOK, w, r)
return
return true
}
http.Error(w, "unkown response type", http.StatusBadRequest)
return false
}
func corsHandler(h http.Handler) http.Handler {

View file

@ -1,7 +1,7 @@
import { useContext } from "react";
import { useQuery } from "react-query";
import { isUserId } from "../services/isUserId";
import { QueryDefaults, store } from "../store";
import { store } from "../store";
export type AvailableLogs = Array<{ month: string, year: string }>;
@ -27,13 +27,13 @@ export function useAvailableLogs(channel: string | null, username: string | null
.then((data: { availableLogs: AvailableLogs }) => data.availableLogs)
.catch(() => {
setState({ ...state, error: true });
return [];
});
}
return [];
}, QueryDefaults);
}, { refetchOnWindowFocus: false, refetchOnReconnect: false });
return data ?? [];
}

View file

@ -1,7 +1,7 @@
import { useContext } from "react";
import { useQuery } from "react-query";
import { isUserId } from "../services/isUserId";
import { QueryDefaults, store } from "../store";
import { store } from "../store";
import { Emote, LogMessage, UserLogResponse } from "../types/log";
@ -34,7 +34,7 @@ export function useLog(channel: string, username: string, year: string, month: s
}
return [];
}, QueryDefaults);
}, { refetchOnWindowFocus: false, refetchOnReconnect: false });
return data ?? [];
}

View file

@ -27,7 +27,7 @@ const url = new URL(window.location.href);
const defaultContext = {
state: {
queryCache: new QueryCache(),
apiBaseUrl: process.env.REACT_APP_API_BASE_URL,
apiBaseUrl: process.env.REACT_APP_API_BASE_URL ?? window.location.protocol + "//" + window.location.host,
settings: {
showEmotes: {
displayName: "Show Emotes",