2023-12-22 22:05:30 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var onePixelGIF = []byte{
|
|
|
|
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
|
|
|
|
0x01, 0x00, 0x80, 0xff, 0x00, 0xff, 0xff, 0xff,
|
|
|
|
0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
|
|
|
|
0x01, 0x00, 0x3b,
|
|
|
|
}
|
|
|
|
|
|
|
|
func Server() {
|
2023-12-22 22:23:01 +01:00
|
|
|
db = initDB(getenv("DATA", ".") + "/data.sqlite")
|
2023-12-22 22:05:30 +01:00
|
|
|
|
|
|
|
http.HandleFunc("/new", newPixelPageHandler)
|
|
|
|
http.HandleFunc("/create-pixel", createPixelHandler)
|
|
|
|
http.HandleFunc("/p/", pixelHandler)
|
2023-12-23 20:29:53 +01:00
|
|
|
http.HandleFunc("/", dashboardHandler)
|
2023-12-22 22:05:30 +01:00
|
|
|
|
2023-12-23 16:03:15 +01:00
|
|
|
port := getenv("PORT", "80")
|
2023-12-22 22:05:30 +01:00
|
|
|
|
2023-12-23 16:03:15 +01:00
|
|
|
fmt.Printf("Server is up and running on port %s\n", port)
|
2023-12-22 22:05:30 +01:00
|
|
|
|
2023-12-23 16:03:15 +01:00
|
|
|
log.Fatal(http.ListenAndServe(":"+port, nil))
|
2023-12-22 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PixelStats struct {
|
|
|
|
Title string
|
|
|
|
TotalViews int
|
|
|
|
UniqueViews int
|
|
|
|
UUID string
|
|
|
|
}
|