diff --git a/README.md b/README.md index 5d6a226..85c7177 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,27 @@ # wakapi ## Usage +* Create an empty MySQL database * Clone repository -* Copy `.env.example` to `.env` and set config parameters +* Copy `.env.example` to `.env` and set database credentials * Install dependencies: `go get -d ./...` +* Set target port in `config.ini` * Run server: `go run *.go` +* Edit your local `~/.wakatime.cfg` file and add `api_url = https://your.server:someport/api/heartbeat` + +**First run** (create user account): When running the server for the very first time, the database gets populated. Afterwards you have to create yourself a user account. Until proper user sign up and login is implemented, this is done via SQL, like this. +* `mysql -u yourusername -p -H your.hostname` +* `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`) ## Todo -* Persisted (for performance) +* Persisted summaries / aggregations (for performance) * User sign up and log in -* UI / Graphs +* Additional endpoints for retrieving statistics data +* Unit tests + +## 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 -* GPL-v3 @ [Ferdinand Mütsch](https://muetsch.io) \ No newline at end of file +GPL-v3 @ [Ferdinand Mütsch](https://muetsch.io) \ No newline at end of file diff --git a/main.go b/main.go index 7f31c38..0660b3a 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/gorilla/mux" "github.com/jinzhu/gorm" "github.com/joho/godotenv" + "github.com/rs/cors" ini "gopkg.in/ini.v1" "github.com/n1try/wakapi/middlewares" @@ -85,6 +86,11 @@ func main() { // Middlewares authenticate := &middlewares.AuthenticateMiddleware{UserSrvc: userSrvc} + cors := cors.New(cors.Options{ + AllowedOrigins: []string{"*"}, + AllowedHeaders: []string{"*"}, + Debug: false, + }) // Setup Routing router := mux.NewRouter() @@ -98,10 +104,13 @@ func main() { aggreagations.Methods("GET").HandlerFunc(summaryHandler.Get) // Sub-Routes Setup - router.PathPrefix("/api").Handler(negroni.Classic().With( - negroni.HandlerFunc(authenticate.Handle), - negroni.Wrap(apiRouter), - )) + router.PathPrefix("/api").Handler(negroni.Classic(). + With(cors). + With( + negroni.HandlerFunc(authenticate.Handle), + negroni.Wrap(apiRouter), + )) + router.PathPrefix("/").Handler(negroni.Classic().With(negroni.Wrap(http.FileServer(http.Dir("./static"))))) // Listen HTTP portString := "127.0.0.1:" + strconv.Itoa(config.Port) diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..ce92731 --- /dev/null +++ b/static/index.html @@ -0,0 +1,243 @@ + + + + Coding Stats + + + + + + +

Statistics

+
+ + + + + + +
+
+
+

+ Total:
+

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + + + + + + \ No newline at end of file