Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a web ui on /web path #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ VERSION ?= latest

IMG_NAME ?= ghcr.io/ostafen/kronos
IMG_TAG ?= latest

build: vendor
@mkdir -p $(BIN_FOLDER)
cd web && npm run build
go build -mod vendor -a -installsuffix cgo -ldflags '-w -s -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X "main.buildTime=$(BUILD_TIME)"' -o $(BIN_FOLDER)/$(EXEC_NAME) cmd/main.go

generate:
Expand Down
Binary file added cmd/kronos.bolt
Binary file not shown.
7 changes: 6 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/ostafen/kronos/internal/sched"
"github.com/ostafen/kronos/internal/service"
"github.com/ostafen/kronos/internal/store"
statichttp "github.com/ostafen/kronos/web"
"github.com/prometheus/client_golang/prometheus/promhttp"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -148,8 +148,12 @@ func getFormatter(format string) log.Formatter {
}

func configureRouter(svc service.ScheduleService) {
a := statichttp.Static

r := mux.NewRouter()

fs := http.FileServer(http.FS(a))
r.PathPrefix("/web").Handler(http.StripPrefix("/", fs))
scheduleApi := api.NewScheduleApi(svc)

r.Handle("/metrics", promhttp.Handler()).Methods("GET")
Expand All @@ -162,6 +166,7 @@ func configureRouter(svc service.ScheduleService) {
r.HandleFunc("/schedules/{id}/pause", scheduleApi.PauseSchedule).Methods("POST")
r.HandleFunc("/schedules/{id}/resume", scheduleApi.ResumeSchedule).Methods("POST")
r.HandleFunc("/schedules/{id}/trigger", scheduleApi.TriggerSchedule).Methods("POST")
// r.PathPrefix("/").Handler(http.FileServer(http.Dir("../web/build/")))

http.Handle("/", r)
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules

# Output
.output
.vercel
/.svelte-kit
/build
/web

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions web/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
38 changes: 38 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# create-svelte

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```bash
# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
6 changes: 6 additions & 0 deletions web/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package statichttp

import "embed"

//go:embed web/*
var Static embed.FS
Loading