main.go 1.12 KB
Newer Older
1
2
3
4
5
package main

import (
	"net/http"
	"log"
6
7
	"github.com/gorilla/mux"
	"github.com/gorilla/handlers"
8
9

	oktaUtils "github.com/okta/samples-golang/resource-server/utils"
10
11

	"serviceAPI/service"
12
13
)

14
// TODO: Wrap "service.Authenticate()" around methods when done testing
15
16
func main() {
	oktaUtils.ParseEnvironment()
17
	router := mux.NewRouter()
18

19
20
21
22
23
	// Message Request Endpoints
	router.HandleFunc("/api/messages", service.GetMessages()).Methods("GET")

	// User Request Endpoints
	router.HandleFunc("/api/get-users", service.GetUsers()).Methods("GET")
24
25
	router.HandleFunc("/api/create-user", service.CreateUser()).Methods("POST")
	router.HandleFunc("/api/remove-user", service.RemoveUser()).Methods("DELETE")
26

27
28
	
	// Setup cors
29
	originsOK := handlers.AllowedOrigins([]string{"http://localhost:3000"})
30
31
	headersOk := handlers.AllowedHeaders([]string{"Authorization"})
	methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
32

33
34
35
	// Start server and listen for requests
	log.Print("server starting at localhost:3030 ... ")
	log.Fatal(http.ListenAndServe("localhost:3030", handlers.CORS(originsOK, headersOk, methodsOk)(router)))
36
}