ExpiryDatesManager/server/main.go

51 lines
2.2 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)
router.Methods("OPTIONS").HandlerFunc(
func(w http.ResponseWriter, r *http.Request){
})
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/products/{id}", controllers.DeleteProduct).Methods("DELETE")
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/companies/{id}", controllers.DeleteCompany).Methods("DELETE")
2019-01-05 16:19:24 +01:00
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")
2019-01-05 16:19:24 +01:00
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")
2019-01-05 16:19:24 +01:00
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
}