51 lines
2.2 KiB
Go
51 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"ExpiryDatesManager/server/model"
|
|
"ExpiryDatesManager/server/controllers"
|
|
"ExpiryDatesManager/server/middleware"
|
|
"fmt"
|
|
"net/http"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Printf("hello, world\n")
|
|
router := mux.NewRouter()
|
|
|
|
router.Use(middleware.JwtAuthentication)
|
|
|
|
router.Methods("OPTIONS").HandlerFunc(
|
|
func(w http.ResponseWriter, r *http.Request){
|
|
})
|
|
|
|
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/products/{id}", controllers.DeleteProduct).Methods("DELETE")
|
|
router.HandleFunc("/api/companies", controllers.GetCompanies).Methods("GET")
|
|
router.HandleFunc("/api/companies", controllers.CreateOrUpdateCompany).Methods("POST")
|
|
router.HandleFunc("/api/companies/{id}", controllers.DeleteCompany).Methods("DELETE")
|
|
router.HandleFunc("/api/reports", controllers.CreateOrUpdateReport).Methods("POST")
|
|
router.HandleFunc("/api/reports/{companyId}", controllers.GetReportsForCompany).Methods("GET")
|
|
router.HandleFunc("/api/reportPositions/{reportId}", controllers.GetReportWithPositions).Methods("GET")
|
|
router.HandleFunc("/api/expiryPositions", controllers.GetPositions).Methods("GET")
|
|
router.HandleFunc("/api/expiryPositions", controllers.CreateOrUpdatePosition).Methods("POST")
|
|
router.HandleFunc("/api/expiryPositions/{id}", controllers.DeletePosition).Methods("DELETE")
|
|
router.HandleFunc("/api/expiryPositions/{companyId}", controllers.GetPositionsForCompany).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"))))
|
|
|
|
defer model.GetDB().Close()
|
|
|
|
err := http.ListenAndServe(":"+"8000", router)
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
}
|
|
|
|
fmt.Println("udalo sie")
|
|
}
|