Captain Hook - Web hook server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
997 B

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. )
  7. // func init() {
  8. // // Loads values from .env into the system
  9. // if err := godotenv.Load(); err != nil {
  10. // log.Println("No .env file found")
  11. // }
  12. // }
  13. func main() {
  14. var err error
  15. db, err = connectDB()
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. defer db.Close()
  20. go pingDB(db)
  21. // Get listen address and port
  22. addr, exists := os.LookupEnv("LISTEN")
  23. checkExists(exists, "Couldn't find listen address")
  24. port, exists := os.LookupEnv("PORT")
  25. checkExists(exists, "Couldn't find port")
  26. // Handle hooks
  27. http.HandleFunc("/hook/", hookHandler)
  28. http.HandleFunc("/", index)
  29. http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("html/css"))))
  30. http.Handle("/imgs/", http.StripPrefix("/imgs/", http.FileServer(http.Dir("html/imgs"))))
  31. http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("html/js"))))
  32. // Start the server
  33. log.Println("Starting server")
  34. log.Fatal(http.ListenAndServe(addr+":"+port, nil))
  35. }