Skip to content

Commit b28a7d0

Browse files
committed
Redirect / from browser to /ui
1 parent 1b05146 commit b28a7d0

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

pkg/server/server.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ func (s *Server) Connect(session *melody.Session) {
234234
}
235235

236236
func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
237+
isUpgrade := strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade")
238+
isBrowser := strings.Contains(strings.ToLower(req.Header.Get("User-Agent")), "mozilla")
239+
isAjax := req.Header.Get("X-Requested-With") != ""
240+
241+
if req.URL.Path == "/" && isBrowser && !isAjax && !isUpgrade {
242+
rw.Header().Set("Location", "/ui/")
243+
rw.WriteHeader(302)
244+
return
245+
}
246+
247+
if req.URL.Path == "/favicon.ico" {
248+
http.ServeFileFS(rw, req, static.UI, "/ui/favicon.ico")
249+
return
250+
}
251+
237252
if strings.HasPrefix(req.URL.Path, "/ui") {
238253
path := req.URL.Path
239254
if path == "/ui" || path == "/ui/" {
@@ -250,7 +265,7 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
250265
case http.MethodPost:
251266
s.run(rw, req)
252267
case http.MethodGet:
253-
if req.URL.Path == "/" && strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") {
268+
if req.URL.Path == "/" && isUpgrade {
254269
err := s.melody.HandleRequest(rw, req)
255270
if err != nil {
256271
http.Error(rw, err.Error(), http.StatusInternalServerError)

ui/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build: clean
33
yarn generate
44
rm -rf ../static/ui/_nuxt
55
cp -rp .output/public/* ../static/ui/
6+
touch ../static/ui/_nuxt/_placeholder
67

78
clean:
89
yarn clean

ui/components/left-nav.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const gptList = await useGpts().listAll()
44
const runList = await useRuns().findAll()
55
66
const gptLinks = computed(() => {
7-
return (gptList.value || []).map(x => { return {
7+
return (gptList || []).map(x => { return {
88
label: x,
99
icon: 'i-heroicons-wrench-screwdriver',
1010
to: `/gpt/` + x.split('/').map(y => encodeURIComponent(y)).join('/'),

ui/stores/gpts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const useGpts = defineStore('gpts', {
2727

2828
async listAll() {
2929
const url = useRuntimeConfig().public.api
30-
const { data } = (await useFetch(url) as any as {data: Ref<string[]>})
31-
return data
30+
const data = await $fetch(url, {headers: {'X-Requested-With': 'fetch'} }) as string[]
31+
return reactive(data)
3232
}
3333
}
3434
})

0 commit comments

Comments
 (0)