mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 04:56:30 +00:00
feat: debug-endpoints (#110)
* reorg + pprof endpoints * fix spacing issue * fix generation directory
This commit is contained in:
parent
a4b4fe3454
commit
d151d42081
20 changed files with 105 additions and 61 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -10,5 +10,8 @@
|
||||||
"package.json": "package-lock.json, yarn.lock, .eslintrc.js, tsconfig.json, .prettierrc, .editorconfig, pnpm-lock.yaml, postcss.config.js, tailwind.config.js",
|
"package.json": "package-lock.json, yarn.lock, .eslintrc.js, tsconfig.json, .prettierrc, .editorconfig, pnpm-lock.yaml, postcss.config.js, tailwind.config.js",
|
||||||
"docker-compose.yml": "Dockerfile, .dockerignore, docker-compose.dev.yml, docker-compose.yml",
|
"docker-compose.yml": "Dockerfile, .dockerignore, docker-compose.dev.yml, docker-compose.yml",
|
||||||
"README.md": "LICENSE, SECURITY.md"
|
"README.md": "LICENSE, SECURITY.md"
|
||||||
}
|
},
|
||||||
|
"cSpell.words": [
|
||||||
|
"debughandlers"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
10
Taskfile.yml
10
Taskfile.yml
|
@ -17,13 +17,13 @@ tasks:
|
||||||
deps:
|
deps:
|
||||||
- db:generate
|
- db:generate
|
||||||
cmds:
|
cmds:
|
||||||
- cd backend/app/api/ && swag fmt
|
- cd backend/app/api/static && swag fmt --dir=../
|
||||||
- cd backend/app/api/ && swag init --dir=./,../../internal,../../pkgs
|
- cd backend/app/api/static && swag init --dir=../,../../../internal,../../../pkgs
|
||||||
- |
|
- |
|
||||||
npx swagger-typescript-api \
|
npx swagger-typescript-api \
|
||||||
--no-client \
|
--no-client \
|
||||||
--modular \
|
--modular \
|
||||||
--path ./backend/app/api/docs/swagger.json \
|
--path ./backend/app/api/static/docs/swagger.json \
|
||||||
--output ./frontend/lib/api/types
|
--output ./frontend/lib/api/types
|
||||||
- python3 ./scripts/process-types.py ./frontend/lib/api/types/data-contracts.ts
|
- python3 ./scripts/process-types.py ./frontend/lib/api/types/data-contracts.ts
|
||||||
sources:
|
sources:
|
||||||
|
@ -34,8 +34,8 @@ tasks:
|
||||||
generates:
|
generates:
|
||||||
- "./frontend/lib/api/types/data-contracts.ts"
|
- "./frontend/lib/api/types/data-contracts.ts"
|
||||||
- "./backend/ent/schema"
|
- "./backend/ent/schema"
|
||||||
- "./backend/app/api/docs/swagger.json"
|
- "./backend/app/api/static/docs/swagger.json"
|
||||||
- "./backend/app/api/docs/swagger.yaml"
|
- "./backend/app/api/static/docs/swagger.yaml"
|
||||||
|
|
||||||
api:
|
api:
|
||||||
desc: Starts the backend api server (depends on generate task)
|
desc: Starts the backend api server (depends on generate task)
|
||||||
|
|
16
backend/app/api/handlers/debughandlers/debug.go
Normal file
16
backend/app/api/handlers/debughandlers/debug.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package debughandlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"expvar"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(mux *http.ServeMux) {
|
||||||
|
mux.HandleFunc("/debug/pprof", pprof.Index)
|
||||||
|
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||||
|
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||||
|
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||||
|
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||||
|
mux.Handle("/debug/vars", expvar.Handler())
|
||||||
|
}
|
|
@ -2,13 +2,14 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
atlas "ariga.io/atlas/sql/migrate"
|
atlas "ariga.io/atlas/sql/migrate"
|
||||||
"entgo.io/ent/dialect/sql/schema"
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
"github.com/hay-kot/homebox/backend/app/api/docs"
|
"github.com/hay-kot/homebox/backend/app/api/static/docs"
|
||||||
"github.com/hay-kot/homebox/backend/ent"
|
"github.com/hay-kot/homebox/backend/ent"
|
||||||
"github.com/hay-kot/homebox/backend/internal/config"
|
"github.com/hay-kot/homebox/backend/internal/config"
|
||||||
"github.com/hay-kot/homebox/backend/internal/migrations"
|
"github.com/hay-kot/homebox/backend/internal/migrations"
|
||||||
|
@ -153,5 +154,14 @@ func run(cfg *config.Config) error {
|
||||||
app.SetupDemo()
|
app.SetupDemo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Debug.Enabled {
|
||||||
|
debugrouter := app.debugRouter()
|
||||||
|
go func() {
|
||||||
|
if err := http.ListenAndServe(":"+cfg.Debug.Port, debugrouter); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("failed to start debug server")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
return app.server.Start(routes)
|
return app.server.Start(routes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
_ "github.com/hay-kot/homebox/backend/app/api/docs"
|
"github.com/hay-kot/homebox/backend/app/api/handlers/debughandlers"
|
||||||
v1 "github.com/hay-kot/homebox/backend/app/api/v1"
|
v1 "github.com/hay-kot/homebox/backend/app/api/handlers/v1"
|
||||||
|
_ "github.com/hay-kot/homebox/backend/app/api/static/docs"
|
||||||
"github.com/hay-kot/homebox/backend/internal/repo"
|
"github.com/hay-kot/homebox/backend/internal/repo"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
httpSwagger "github.com/swaggo/http-swagger" // http-swagger middleware
|
httpSwagger "github.com/swaggo/http-swagger" // http-swagger middleware
|
||||||
|
@ -23,10 +24,17 @@ const prefix = "/api"
|
||||||
var (
|
var (
|
||||||
ErrDir = errors.New("path is dir")
|
ErrDir = errors.New("path is dir")
|
||||||
|
|
||||||
//go:embed all:public/*
|
//go:embed all:static/public/*
|
||||||
public embed.FS
|
public embed.FS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (a *app) debugRouter() *http.ServeMux {
|
||||||
|
dbg := http.NewServeMux()
|
||||||
|
debughandlers.New(dbg)
|
||||||
|
|
||||||
|
return dbg
|
||||||
|
}
|
||||||
|
|
||||||
// registerRoutes registers all the routes for the API
|
// registerRoutes registers all the routes for the API
|
||||||
func (a *app) newRouter(repos *repo.AllRepos) *chi.Mux {
|
func (a *app) newRouter(repos *repo.AllRepos) *chi.Mux {
|
||||||
registerMimes()
|
registerMimes()
|
||||||
|
|
|
@ -24,6 +24,12 @@ type Config struct {
|
||||||
Swagger SwaggerConf `yaml:"swagger"`
|
Swagger SwaggerConf `yaml:"swagger"`
|
||||||
Demo bool `yaml:"demo"`
|
Demo bool `yaml:"demo"`
|
||||||
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
|
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
|
||||||
|
Debug DebugConf `yaml:"debug"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DebugConf struct {
|
||||||
|
Enabled bool `yaml:"enabled" conf:"default:false"`
|
||||||
|
Port string `yaml:"port" conf:"default:4000"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SwaggerConf struct {
|
type SwaggerConf struct {
|
||||||
|
|
|
@ -124,7 +124,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<BaseContainer>
|
<div>
|
||||||
<BaseModal v-model="updateModal">
|
<BaseModal v-model="updateModal">
|
||||||
<template #title> Update Location </template>
|
<template #title> Update Location </template>
|
||||||
<form v-if="location" @submit.prevent="update">
|
<form v-if="location" @submit.prevent="update">
|
||||||
|
@ -136,59 +136,60 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
|
<BaseContainer class="space-y-10 mb-16">
|
||||||
|
<BaseCard>
|
||||||
|
<template #title>
|
||||||
|
<BaseSectionHeader>
|
||||||
|
<Icon name="mdi-map-marker" class="mr-2 -mt-1 text-base-content" />
|
||||||
|
<span class="text-base-content">
|
||||||
|
{{ location ? location.name : "" }}
|
||||||
|
</span>
|
||||||
|
<div v-if="location && location.parent" class="text-sm breadcrumbs pb-0">
|
||||||
|
<ul class="text-base-content/70">
|
||||||
|
<li>
|
||||||
|
<NuxtLink :to="`/location/${location.parent.id}`"> {{ location.parent.name }}</NuxtLink>
|
||||||
|
</li>
|
||||||
|
<li>{{ location.name }}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</BaseSectionHeader>
|
||||||
|
</template>
|
||||||
|
|
||||||
<BaseCard class="mb-16">
|
<template #title-actions>
|
||||||
<template #title>
|
<div class="flex mt-2 gap-2">
|
||||||
<BaseSectionHeader>
|
<div class="form-control max-w-[160px]">
|
||||||
<Icon name="mdi-map-marker" class="mr-2 -mt-1 text-base-content" />
|
<label class="label cursor-pointer">
|
||||||
<span class="text-base-content">
|
<input v-model="preferences.showDetails" type="checkbox" class="toggle toggle-primary" />
|
||||||
{{ location ? location.name : "" }}
|
<span class="label-text ml-2"> Detailed View </span>
|
||||||
</span>
|
</label>
|
||||||
<div v-if="location && location.parent" class="text-sm breadcrumbs pb-0">
|
</div>
|
||||||
<ul class="text-base-content/70">
|
<BaseButton class="ml-auto" size="sm" @click="openUpdate">
|
||||||
<li>
|
<Icon class="mr-1" name="mdi-pencil" />
|
||||||
<NuxtLink :to="`/location/${location.parent.id}`"> {{ location.parent.name }}</NuxtLink>
|
Edit
|
||||||
</li>
|
</BaseButton>
|
||||||
<li>{{ location.name }}</li>
|
<BaseButton size="sm" @click="confirmDelete">
|
||||||
</ul>
|
<Icon class="mr-1" name="mdi-delete" />
|
||||||
|
Delete
|
||||||
|
</BaseButton>
|
||||||
</div>
|
</div>
|
||||||
</BaseSectionHeader>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #title-actions>
|
<DetailsSection :details="details" />
|
||||||
<div class="flex mt-2 gap-2">
|
</BaseCard>
|
||||||
<div class="form-control max-w-[160px]">
|
|
||||||
<label class="label cursor-pointer">
|
<section v-if="location && location.items.length > 0">
|
||||||
<input v-model="preferences.showDetails" type="checkbox" class="toggle toggle-primary" />
|
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
|
||||||
<span class="label-text ml-2"> Detailed View </span>
|
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2">
|
||||||
</label>
|
<ItemCard v-for="item in location.items" :key="item.id" :item="item" />
|
||||||
</div>
|
|
||||||
<BaseButton class="ml-auto" size="sm" @click="openUpdate">
|
|
||||||
<Icon class="mr-1" name="mdi-pencil" />
|
|
||||||
Edit
|
|
||||||
</BaseButton>
|
|
||||||
<BaseButton size="sm" @click="confirmDelete">
|
|
||||||
<Icon class="mr-1" name="mdi-delete" />
|
|
||||||
Delete
|
|
||||||
</BaseButton>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</section>
|
||||||
|
|
||||||
<DetailsSection :details="details" />
|
<section v-if="location && location.children.length > 0">
|
||||||
</BaseCard>
|
<BaseSectionHeader class="mb-5"> Child Locations </BaseSectionHeader>
|
||||||
|
<div class="grid gap-2 grid-cols-1 sm:grid-cols-3">
|
||||||
<section v-if="location && location.items.length > 0">
|
<LocationCard v-for="item in location.children" :key="item.id" :location="item" />
|
||||||
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
|
</div>
|
||||||
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2">
|
</section>
|
||||||
<ItemCard v-for="item in location.items" :key="item.id" :item="item" />
|
</BaseContainer>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
|
|
||||||
<section v-if="location && location.children.length > 0">
|
|
||||||
<BaseSectionHeader class="mb-5"> Child Locations </BaseSectionHeader>
|
|
||||||
<div class="grid gap-2 grid-cols-1 sm:grid-cols-3">
|
|
||||||
<LocationCard v-for="item in location.children" :key="item.id" :location="item" />
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</BaseContainer>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in a new issue