ExpiryDatesManager/server/main.go

43 lines
1.8 KiB
Go
Raw Normal View History

2018-12-16 16:27:33 +01:00
package main
import (
"ExpiryDatesManager/server/model"
"ExpiryDatesManager/server/controllers"
2019-01-05 16:19:24 +01:00
"ExpiryDatesManager/server/middleware"
2018-12-16 16:27:33 +01:00
"fmt"
"net/http"
"github.com/gorilla/mux"
2018-12-16 16:27:33 +01:00
)
func main() {
fmt.Printf("hello, world\n")
router := mux.NewRouter()
2019-01-05 16:19:24 +01:00
router.Use(middleware.JwtAuthentication)
2019-01-05 16:19:24 +01:00
router.HandleFunc("/api/login", controllers.Authenticate).Methods("POST")
router.HandleFunc("/api/register", controllers.CreateAccount).Methods("POST")
router.HandleFunc("/api/products/{code}", controllers.GetProduct).Methods("GET")
router.HandleFunc("/api/products", controllers.CreateOrUpdateProduct).Methods("POST")
router.HandleFunc("/api/products", controllers.GetProducts).Methods("GET")
router.HandleFunc("/api/companies", controllers.GetCompanies).Methods("GET")
2019-01-05 16:19:24 +01:00
router.HandleFunc("/api/companies", controllers.CreateOrUpdateCompany).Methods("POST")
router.HandleFunc("/api/reports", controllers.CreateOrUpdateReport).Methods("POST")
router.HandleFunc("/api/reports/{companyId}", controllers.GetReportsForCompany).Methods("GET")
router.HandleFunc("/api/expiryPositions", controllers.GetPositions).Methods("GET")
router.HandleFunc("/api/expiryPositions", controllers.CreateOrUpdatePosition).Methods("POST")
router.HandleFunc("/api/reportPositions", controllers.CreateOrUpdatePosition).Methods("POST")
router.HandleFunc("/api/reportPositions", controllers.GetReportsPositionsForReport).Methods("GET")
router.Handle("/", http.FileServer(http.Dir("../client/build")))
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("../client/build/static"))))
router.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("../client/build"))))
2018-12-16 16:27:33 +01:00
defer model.GetDB().Close()
err := http.ListenAndServe(":"+"8000", router)
if err != nil {
fmt.Print(err)
}
2018-12-16 16:27:33 +01:00
fmt.Println("udalo sie")
2018-12-16 16:27:33 +01:00
}