Exemple #1
0
// Serve starts the server
func (a *App) Serve() {
	// External endpoints
	external := web.New()
	external.Use(server.StripTrailingSlashMiddleware())
	external.Use(server.HeadersMiddleware())
	external.Post("/", a.requestHandler.HandlerAuth)
	externalPortString := fmt.Sprintf(":%d", *a.config.ExternalPort)
	log.Println("Starting external server on", externalPortString)
	go func() {
		var err error
		if a.config.TLS.CertificateFile != "" && a.config.TLS.PrivateKeyFile != "" {
			err = graceful.ListenAndServeTLS(
				externalPortString,
				a.config.TLS.CertificateFile,
				a.config.TLS.PrivateKeyFile,
				external,
			)
		} else {
			err = graceful.ListenAndServe(externalPortString, external)
		}

		if err != nil {
			log.Fatal(err)
		}
	}()

	// Internal endpoints
	internal := web.New()
	internal.Use(server.StripTrailingSlashMiddleware())
	internal.Use(server.HeadersMiddleware())
	internal.Post("/send", a.requestHandler.HandlerSend)
	internal.Post("/receive", a.requestHandler.HandlerReceive)
	internal.Post("/allow_access", a.requestHandler.HandlerAllowAccess)
	internal.Post("/remove_access", a.requestHandler.HandlerRemoveAccess)
	internalPortString := fmt.Sprintf(":%d", *a.config.InternalPort)
	log.Println("Starting internal server on", internalPortString)
	err := graceful.ListenAndServe(internalPortString, internal)
	if err != nil {
		log.Fatal(err)
	}
}
Exemple #2
0
// Serve starts the server
func (a *App) Serve() {
	portString := fmt.Sprintf(":%d", *a.config.Port)
	flag.Set("bind", portString)

	goji.Abandon(middleware.Logger)
	goji.Use(server.StripTrailingSlashMiddleware())
	goji.Use(server.HeadersMiddleware())
	if a.config.APIKey != "" {
		goji.Use(server.APIKeyMiddleware(a.config.APIKey))
	}

	if a.config.Accounts.AuthorizingSeed != "" {
		goji.Post("/authorize", a.requestHandler.Authorize)
	} else {
		log.Warning("accounts.authorizing_seed not provided. /authorize endpoint will not be available.")
	}

	goji.Post("/create-keypair", a.requestHandler.CreateKeypair)
	goji.Post("/builder", a.requestHandler.Builder)
	goji.Post("/payment", a.requestHandler.Payment)
	goji.Get("/payment", a.requestHandler.Payment)

	goji.Serve()
}