Beispiel #1
0
func main() {

	//Setup router
	router := mux.NewRouter()
	handlers.ConfigUserHandler(router.PathPrefix("/user").Subrouter())
	handlers.ConfigFormHandler(router.PathPrefix("/form").Subrouter())
	handlers.ConfigMiscHandlers(router.PathPrefix("/misc").Subrouter())
	handlers.ConfigReviewHandler(router.PathPrefix("/review").Subrouter())
	handlers.ConfigRecommHandler(router.PathPrefix("/recomm").Subrouter())
	handlers.ConfigAdminHandler(router.PathPrefix("/gm").Subrouter())

	http.Handle("/", router)

	//Setup CORS Options
	origins := make([]string, 1)
	origins[0] = "*"
	allowOrigins := goHandlers.AllowedOrigins(origins)

	addrStr := fmt.Sprintf("%s:%d",
		public.Config.GetString("server.address"),
		public.Config.GetInt("server.port"))
	public.LogV.Printf("Listen address: %s\n", addrStr)
	public.LogE.Fatal(http.ListenAndServe(
		addrStr,
		context.ClearHandler(goHandlers.CORS(allowOrigins)(http.DefaultServeMux)),
	))
}
Beispiel #2
0
func ServeFromGolog(g *gologme.Golog, url string) {
	golog = g

	router := mux.NewRouter()
	RegisterRoutes(router)

	// Listen and serve
	fmt.Printf("Listening on %s ...\n", url)
	log.Fatal(http.ListenAndServe(url,
		handlers.CORS(
			handlers.AllowedOrigins([]string{"http://localhost:3000"}),
			handlers.AllowedMethods([]string{"POST", "GET", "HEAD", "OPTIONS"}),
			handlers.AllowedHeaders([]string{"Authorization", "Content-Type"}),
			handlers.AllowCredentials(),
		)(router)))
}
func main() {

	flag.Parse()

	config, err := infrastructure.GetConfiguration(*confFilePath)
	if err != nil {
		fmt.Println(err.Error())
		panic("Cannot parse configuration")
	}

	doInteractor := usecases.DOInteractor{}

	handler := interfaces.WebServiceHandler{
		Interactor:  doInteractor,
		ID:          config.ClientID,
		Secret:      config.ClientSecret,
		Scopes:      config.Scopes,
		RedirectURI: config.RedirectURI,
		APIHost:     config.APIHost,
	}

	headers := handlers.AllowedHeaders([]string{"Accept", "Content-Type", "Authorization"})
	origins := handlers.AllowedOrigins([]string{"http://localhost", "http://provision.tinkerware.io", "https://provision.tinkerware.io"})

	r := mux.NewRouter()

	subrouter := r.PathPrefix("/api/v1/cloud").Subrouter()

	subrouter.HandleFunc("/digital_ocean/", handler.Login)
	subrouter.HandleFunc("/digital_ocean/oauth", handler.DOCallback).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/keys", handler.ShowKeys).Methods("GET")
	subrouter.HandleFunc("/digital_ocean/keys", handler.CreateKey).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/instances", handler.CreateDroplet).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/instances", handler.ListDroplets).Methods("GET")
	subrouter.HandleFunc("/digital_ocean/instance/{instanceID}", handler.GetInstance).Methods("GET")

	n := negroni.Classic()
	n.UseHandler(handlers.CORS(headers, origins)(r))

	port := bytes.Buffer{}

	port.WriteString(":")
	port.WriteString(config.Port)

	n.Run(port.String())

}