mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Add ability to listen on public interface.
Add ability to handle unknown keys. Update Readme.
This commit is contained in:
parent
f7d2a39a00
commit
86fe3a4bae
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
launch.json
|
||||
.vscode
|
||||
.env
|
||||
.env
|
||||
wakapi
|
11
README.md
11
README.md
@ -1,4 +1,4 @@
|
||||
# wakapi
|
||||
# 📈 wakapi - A WakaTime-compatible backend for coding statistics
|
||||
|
||||
## Usage
|
||||
* Create an empty MySQL database
|
||||
@ -15,14 +15,21 @@
|
||||
* `USE yourdatabasename;`
|
||||
* `INSERT INTO users (id, api_key) VALUES ('your_cool_nickname', '728f084c-85e0-41de-aa2a-b6cc871200c1');` (the latter value is your api key from `~/.wakatime.cfg`)
|
||||
|
||||
## Best Practices
|
||||
It is recommended to use wakapi behind a **reverse proxy**, like [Caddy](https://caddyserver.com) or _nginx_ to enable **TLS encryption** (HTTPS).
|
||||
However, if you want to expose your wakapi instance to the public anyway, you need to set `listen = 0.0.0.0` in `config.ini`
|
||||
|
||||
## Todo
|
||||
* Persisted summaries / aggregations (for performance)
|
||||
* User sign up and log in
|
||||
* Additional endpoints for retrieving statistics data
|
||||
* Enhanced UI
|
||||
* Loading spinner
|
||||
* Responsiveness
|
||||
* Dockerize
|
||||
* Unit tests
|
||||
|
||||
## Important note
|
||||
## Important Note
|
||||
**This is not an alternative to using WakaTime.** It is just a custom, non-commercial, self-hosted application to collect coding statistics using the already existing editor plugins provided by the WakaTime community. It was created for personal use only and with the purpose of keeping the sovereignity of your own data. However, if you like the official product, **please support the authors and buy an official WakaTime subscription!**
|
||||
|
||||
## License
|
||||
|
@ -1,2 +1,3 @@
|
||||
[server]
|
||||
listen = 127.0.0.1
|
||||
port = 3000
|
10
main.go
10
main.go
@ -43,6 +43,7 @@ func readConfig() *models.Config {
|
||||
log.Fatal(fmt.Sprintf("Fail to read file: %v", err))
|
||||
}
|
||||
|
||||
addr := cfg.Section("server").Key("listen").MustString("127.0.0.1")
|
||||
port, err := strconv.Atoi(os.Getenv("PORT"))
|
||||
if err != nil {
|
||||
port = cfg.Section("server").Key("port").MustInt()
|
||||
@ -50,6 +51,7 @@ func readConfig() *models.Config {
|
||||
|
||||
return &models.Config{
|
||||
Port: port,
|
||||
Addr: addr,
|
||||
DbHost: dbHost,
|
||||
DbUser: dbUser,
|
||||
DbPassword: dbPassword,
|
||||
@ -65,6 +67,8 @@ func main() {
|
||||
// Connect to database
|
||||
db, err := gorm.Open(config.DbDialect, utils.MakeConnectionString(config))
|
||||
db.LogMode(false)
|
||||
db.DB().SetMaxIdleConns(1)
|
||||
db.DB().SetMaxOpenConns(10)
|
||||
if err != nil {
|
||||
// log.Fatal("Could not connect to database.")
|
||||
log.Fatal(err)
|
||||
@ -98,10 +102,10 @@ func main() {
|
||||
|
||||
// API Routes
|
||||
heartbeats := apiRouter.Path("/heartbeat").Subrouter()
|
||||
heartbeats.Methods("POST").HandlerFunc(heartbeatHandler.Post)
|
||||
heartbeats.Methods(http.MethodPost).HandlerFunc(heartbeatHandler.Post)
|
||||
|
||||
aggreagations := apiRouter.Path("/summary").Subrouter()
|
||||
aggreagations.Methods("GET").HandlerFunc(summaryHandler.Get)
|
||||
aggreagations.Methods(http.MethodGet).HandlerFunc(summaryHandler.Get)
|
||||
|
||||
// Sub-Routes Setup
|
||||
router.PathPrefix("/api").Handler(negroni.Classic().
|
||||
@ -113,7 +117,7 @@ func main() {
|
||||
router.PathPrefix("/").Handler(negroni.Classic().With(negroni.Wrap(http.FileServer(http.Dir("./static")))))
|
||||
|
||||
// Listen HTTP
|
||||
portString := "127.0.0.1:" + strconv.Itoa(config.Port)
|
||||
portString := config.Addr + ":" + strconv.Itoa(config.Port)
|
||||
s := &http.Server{
|
||||
Handler: router,
|
||||
Addr: portString,
|
||||
|
@ -2,6 +2,7 @@ package models
|
||||
|
||||
type Config struct {
|
||||
Port int
|
||||
Addr string
|
||||
DbHost string
|
||||
DbUser string
|
||||
DbPassword string
|
||||
|
@ -77,7 +77,7 @@ func (srv *SummaryService) aggregateBy(heartbeats []*models.Heartbeat, summaryTy
|
||||
}
|
||||
|
||||
if key == "" {
|
||||
continue
|
||||
key = "unknown"
|
||||
}
|
||||
|
||||
if _, ok := durations[key]; !ok {
|
||||
|
@ -11,7 +11,7 @@
|
||||
}
|
||||
|
||||
.grid-container {
|
||||
width: 60%;
|
||||
width: 75%;
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
'header header header'
|
||||
|
Loading…
Reference in New Issue
Block a user