Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
daf169e
fix(search): use OS temp dir if no indexPath is set
marle3003 Feb 26, 2026
d4cc11b
feat(api): provide health checks
marle3003 Feb 26, 2026
25ecc0d
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 26, 2026
a3bc0d3
fix: update links
marle3003 Feb 26, 2026
d1c9ff6
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 26, 2026
e62b94f
fix: fix test
marle3003 Feb 26, 2026
a6a8dd5
doc: add health endpoints to documentation
marle3003 Feb 27, 2026
dbd5d41
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 27, 2026
598ab1e
build(deps): bump github.com/go-git/go-git/v5 from 5.16.5 to 5.17.0
dependabot[bot] Feb 27, 2026
8621aa8
build(deps-dev): bump eslint-plugin-vue from 10.7.0 to 10.8.0 in /webui
dependabot[bot] Feb 27, 2026
6ceca10
build(deps): bump golang.org/x/net from 0.50.0 to 0.51.0
dependabot[bot] Feb 27, 2026
07032dc
Merge pull request #857 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Feb 27, 2026
77b7397
build(deps-dev): bump @types/node from 25.2.3 to 25.3.2 in /webui
dependabot[bot] Feb 27, 2026
77bdc42
Merge pull request #861 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Feb 27, 2026
61d8321
build(deps): bump @types/whatwg-mimetype from 3.0.2 to 5.0.0 in /webui
dependabot[bot] Feb 27, 2026
b1903c5
Merge pull request #859 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Feb 27, 2026
a2704a5
build(deps): bump vue-router from 5.0.2 to 5.0.3 in /webui
dependabot[bot] Feb 27, 2026
320daaa
Merge pull request #860 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Feb 27, 2026
8c7eb44
fix(git): fix pull repository
marle3003 Feb 27, 2026
9c1cce2
chore: add debug log message
marle3003 Feb 27, 2026
41a8761
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 27, 2026
fb0a4e5
chore: add debug log message
marle3003 Feb 27, 2026
3cf1f69
chore: remove debug log message
marle3003 Feb 27, 2026
cac0f00
chore: add debug log message
marle3003 Feb 27, 2026
b84d7cf
chore: add debug log message
marle3003 Feb 27, 2026
0ec47b5
fix: npm release
marle3003 Feb 27, 2026
81e06f5
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 27, 2026
311fb48
Merge branch 'develop' into dependabot/go_modules/develop/github.com/…
marle3003 Feb 27, 2026
fcca4f4
feat(health): add health check on default port 8080 and path /health
marle3003 Feb 28, 2026
cf26065
Merge branch 'develop' into dependabot/go_modules/develop/golang.org/…
marle3003 Feb 28, 2026
eaed9cc
Merge pull request #858 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Feb 28, 2026
bf9848e
Merge branch 'develop' into dependabot/go_modules/develop/github.com/…
marle3003 Feb 28, 2026
eb8bbca
Merge pull request #856 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Feb 28, 2026
d20ddc3
Merge branch 'main' into develop
marle3003 Feb 28, 2026
f1f98b4
chore(pipeline): remove NPM token
marle3003 Feb 28, 2026
3450d00
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Feb 28, 2026
b3a958b
doc: add health check documentation
marle3003 Feb 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.25.5
- run: npm install -g npm@latest
- uses: ./.github/actions/build-release-notes
- uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tasks:
dir: npm
cmds:
- npm version {{.VERSION}}
- npm publish
- npm publish --provenance
npm-build-windows:
cmds:
- go build -o ./npm/dist/mokapi-windows-amd64/mokapi.exe -ldflags="-X mokapi/version.BuildVersion={{.VERSION}}" ./cmd/mokapi
Expand Down
18 changes: 17 additions & 1 deletion acceptance/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"mokapi/config/static"
"mokapi/engine"
"mokapi/feature"
"mokapi/health"
"mokapi/providers/asyncapi3"
"mokapi/providers/directory"
mail2 "mokapi/providers/mail"
Expand Down Expand Up @@ -63,14 +64,29 @@ func Start(cfg *static.Config) (*Cmd, error) {
app.UpdateConfig(e)
})

apiHandler := api.New(app, cfg.Api)
if u, err := api.BuildUrl(cfg.Api); err == nil {
err = http.AddInternalService("api", u, api.New(app, cfg.Api))
err = http.AddInternalService("api", u, apiHandler)
if err != nil {
return nil, err
}
} else {
return nil, err
}
if cfg.Health.Enabled {
if u, err := health.BuildUrl(cfg.Health); err == nil {
if cfg.Api.Port == cfg.Health.Port {
apiHandler.RegisterHealthHandler(u.Path, health.New(cfg.Health))
} else {
err = http.AddInternalService("health", u, health.New(cfg.Health))
if err != nil {
return nil, err
}
}
} else {
return nil, err
}
}

pool := safe.NewPool(context.Background())
s := server.NewServer(pool, app, watcher, kafka, http, mailManager, ldap, scriptEngine)
Expand Down
8 changes: 8 additions & 0 deletions acceptance/petstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PetStoreSuite struct{ BaseSuite }
func (suite *PetStoreSuite) SetupSuite() {
cfg := static.NewConfig()
cfg.Api.Port = try.GetFreePort()
cfg.Health.Port = cfg.Api.Port
cfg.Providers.File.Directories = []static.FileConfig{{Path: "./petstore"}}
cfg.Api.Search.Enabled = true
suite.initCmd(cfg)
Expand Down Expand Up @@ -392,3 +393,10 @@ func (suite *PetStoreSuite) TestSearch_Paging() {
}),
)
}

func (suite *PetStoreSuite) TestHealth() {
try.GetRequest(suite.T(), fmt.Sprintf("http://127.0.0.1:%v/health", suite.cfg.Api.Port), nil,
try.HasStatusCode(http.StatusOK),
try.HasBody(`{"status":"healthy"}`),
)
}
28 changes: 21 additions & 7 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ import (
log "github.com/sirupsen/logrus"
)

type Handler interface {
http.Handler
RegisterHealthHandler(path string, h http.Handler)
}

type handler struct {
config static.Api
path string
base string
app *runtime.App
fileServer http.Handler
index string
config static.Api
path string
base string
app *runtime.App
fileServer http.Handler
index string
healthPath string
healthHandler http.Handler
}

type info struct {
Expand Down Expand Up @@ -67,7 +74,7 @@ type apiError struct {
Message string `json:"message"`
}

func New(app *runtime.App, config static.Api) http.Handler {
func New(app *runtime.App, config static.Api) Handler {
h := &handler{
config: config,
path: config.Path,
Expand Down Expand Up @@ -99,6 +106,11 @@ func BuildUrl(cfg static.Api) (*url.URL, error) {
return url.Parse(s)
}

func (h *handler) RegisterHealthHandler(path string, handler http.Handler) {
h.healthPath = path
h.healthHandler = handler
}

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" && r.Method != "POST" {
http.Error(w, fmt.Sprintf("method %v is not allowed", r.Method), http.StatusMethodNotAllowed)
Expand Down Expand Up @@ -140,6 +152,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.handleFakerTree(w, r)
case strings.HasPrefix(p, "/api/search"):
h.getSearchResults(w, r)
case strings.HasPrefix(p, h.healthPath) && h.healthHandler != nil:
h.healthHandler.ServeHTTP(w, r)
case h.fileServer != nil:
if r.Method != "GET" {
http.Error(w, fmt.Sprintf("method %v is not allowed", r.Method), http.StatusMethodNotAllowed)
Expand Down
54 changes: 54 additions & 0 deletions api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api_test
import (
"mokapi/api"
"mokapi/config/static"
"mokapi/health"
"mokapi/providers/openapi"
"mokapi/runtime"
"mokapi/runtime/runtimetest"
Expand Down Expand Up @@ -207,3 +208,56 @@ func TestHandler_SearchEnabled(t *testing.T) {
try.HasHeader("Content-Type", "application/json"),
try.HasBody(`{"version":"0.0.0","buildTime":"","search":{"enabled":true}}`))
}

func TestHandler_Health(t *testing.T) {
testcases := []struct {
name string
cfg *static.Config
test func(t *testing.T, h http.Handler)
}{
{
name: "POST is not allowed",
cfg: &static.Config{},
test: func(t *testing.T, h http.Handler) {
r := httptest.NewRequest(http.MethodPatch, "http://foo.api/health", nil)
rr := httptest.NewRecorder()
h.ServeHTTP(rr, r)
require.Equal(t, http.StatusMethodNotAllowed, rr.Code)
},
},
{
name: "GET /health",
cfg: &static.Config{},
test: func(t *testing.T, h http.Handler) {
r := httptest.NewRequest(http.MethodGet, "http://foo.api/health", nil)
rr := httptest.NewRecorder()
h.ServeHTTP(rr, r)
require.Equal(t, http.StatusOK, rr.Code)
require.Equal(t, `{"status":"healthy"}`, rr.Body.String())
},
},
{
name: "use path but request does not adapt",
cfg: &static.Config{Api: static.Api{Path: "/foo"}},
test: func(t *testing.T, h http.Handler) {
r := httptest.NewRequest(http.MethodGet, "http://foo.api/health", nil)
rr := httptest.NewRecorder()
h.ServeHTTP(rr, r)
require.Equal(t, http.StatusOK, rr.Code)
require.Equal(t, `{"status":"healthy"}`, rr.Body.String())
},
},
}

t.Parallel()
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

h := api.New(runtime.New(tc.cfg), tc.cfg.Api)
h.RegisterHealthHandler("/health", health.New(static.Health{}))
tc.test(t, h)
})
}
}
5 changes: 5 additions & 0 deletions cmd/mokapi/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ api:
enabled: true
indexPath: ""
inMemory: false
health:
enabled: true
path: /health
port: 8080
log: false
rootCaCert: ""
rootCaKey: ""
configs: []
Expand Down
5 changes: 2 additions & 3 deletions config/dynamic/provider/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/client"
"github.com/go-git/go-git/v5/plumbing/transport/http"
Expand Down Expand Up @@ -271,9 +270,9 @@ func pull(r *repository) {
if r.repo == nil {
return
}
err := r.repo.Fetch(&git.FetchOptions{RefSpecs: []config.RefSpec{"refs/*:refs/*", "HEAD:refs/heads/HEAD"}})
err := r.repo.Fetch(&git.FetchOptions{})
if errors.Is(err, git.ErrForceNeeded) {
err = r.repo.Fetch(&git.FetchOptions{RefSpecs: []config.RefSpec{"+refs/*:refs/*", "HEAD:refs/heads/HEAD"}})
err = r.repo.Fetch(&git.FetchOptions{})
}
if err != nil {
if !errors.Is(err, git.NoErrAlreadyUpToDate) {
Expand Down
12 changes: 12 additions & 0 deletions config/static/static_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Config struct {
ConfigFile string `json:"-" yaml:"-" flag:"config-file"`
Providers Providers `json:"providers" yaml:"providers"`
Api Api `json:"api" yaml:"api"`
Health Health `json:"health" yaml:"health"`
RootCaCert tls.FileOrContent `json:"rootCaCert" yaml:"rootCaCert" name:"root-ca-cert"`
RootCaKey tls.FileOrContent `json:"rootCaKey" yaml:"rootCaKey" name:"root-ca-cert"`
Configs Configs `json:"configs" yaml:"configs" explode:"config"`
Expand All @@ -39,6 +40,10 @@ func NewConfig() *Config {
cfg.Api.Dashboard = true
cfg.Api.Search.Enabled = true

cfg.Health.Enabled = true
cfg.Health.Port = 8080
cfg.Health.Path = "/health"

cfg.Providers.File.SkipPrefix = []string{"_"}
cfg.Event.Store = map[string]Store{"default": {Size: 100}}
cfg.DataGen.OptionalProperties = "0.85"
Expand Down Expand Up @@ -286,3 +291,10 @@ func (fc *FileConfig) Set(v any) error {
}
return fmt.Errorf("expected string, got %T", v)
}

type Health struct {
Enabled bool `yaml:"enabled" json:"enabled"`
Path string `yaml:"path" json:"path"`
Port int `yaml:"port" json:"port"`
Log bool `yaml:"log" json:"log"`
}
5 changes: 5 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
"path": "/docs/configuration/reference"
}
]
},
{
"label": "Health Check",
"source": "configuration/healthcheck.md",
"path": "/docs/configuration/health-check"
}
]
},
Expand Down
Loading
Loading