main.go 972 Bytes
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
15
)

func main() {
	oktaUtils.ParseEnvironment()
16
	router := mux.NewRouter()
17

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")
	router.HandleFunc("/api/create-user", service.CreateUser()).Methods("POST")
24

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

31
32
33
	// 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)))
34
}