示例#1
0
func selectSubdomain(appID string, required bool) {
	app, _ := account.GetAppByID(appID)
	log.Debugf("Subdomain app: %v", app)
	for {
		if required {
			app.HostingSubdomain = term.GetString("Choose a *.appstax.io subdomain for hosting")
		} else {
			term.Println("Choose a *.appstax.io subdomain for hosting:")
			term.Println("(Leave this blank if you wish to decide this later.)")
			app.HostingSubdomain = term.GetString("Subdomain")
		}

		if app.HostingSubdomain != "" {
			err1 := account.SaveApp(app)
			if err1 != nil {
				term.Println(err1.Error())
			}
			err2 := account.AddCorsOrigin(appID, fmt.Sprintf("http://%s.appstax.io", app.HostingSubdomain))
			if err2 != nil {
				term.Println(err2.Error())
			}
			if err1 == nil && err2 == nil {
				term.Printf("Successfully configured %s.appstax.io\n", app.HostingSubdomain)
				return
			}
		} else if !required {
			return
		}
	}
}
示例#2
0
func selectPublicDir() string {
	dir := term.GetString("Select deployable directory [default: ./public]")
	if dir == "" {
		dir = "./public"
	}
	return dir
}
示例#3
0
func DoSignup(c *cli.Context) {
	useOptions(c)
	term.Println("By signing up you agree to our terms of service:")
	term.Println("https://appstax.com/admin/#/tos")
	term.Section()
	for {
		firstName := term.GetString("First name")
		lastName := term.GetString("Last name")
		email := term.GetString("Email")
		password := term.GetPassword("Password")
		sessionID, userID, accountID, err := account.Signup(firstName, lastName, email, password)
		if err != nil {
			term.Section()
			term.Println(err.Error())
		} else {
			writeSession(sessionID, userID, accountID)
			term.Section()
			term.Println(fmt.Sprintf("Account created for '%s'", email))
			return
		}
	}
}
示例#4
0
func login() {
	for {
		email := term.GetString("Email")
		password := term.GetPassword("Password")
		sessionID, userID, accountID, err := account.Login(email, password)
		if err != nil {
			term.Section()
			term.Println(err.Error())
		} else {
			writeSession(sessionID, userID, accountID)
			term.Section()
			term.Println(fmt.Sprintf("Successfully logged in as '%s'", email))
			return
		}
	}
}
示例#5
0
func DoServer(c *cli.Context) {
	useOptions(c)
	if !config.Exists() {
		term.Println("Can't find appstax.conf. Run 'appstax init' to initialize before deploying.")
		return
	}
	loginIfNeeded()

	args := c.Args()
	if len(args) == 0 {
		term.Println("Too few arguments. Usage: appstax server create|delete|status|start|stop|log")
		return
	}

	operation := args[0]
	switch operation {
	case "create":
		selectSubdomainIfNeeded()
		accessCode := term.GetString("Please enter early access code")
		err := hosting.CreateServer(accessCode)
		if err == nil {
			term.Println("Server created successfully!")
		} else {
			term.Println("Error creating server:")
			term.Println(err.Error())
		}
	case "delete":
		err := hosting.DeleteServer()
		if err == nil {
			term.Println("Server deleted!")
		} else {
			term.Println("Error deleting server:")
			term.Println(err.Error())
		}
	case "status":
		status, err := hosting.GetServerStatus()
		if err == nil {
			term.Println("Server status: " + status.Status)
		} else {
			term.Println("Error getting server status:")
			term.Println(err.Error())
		}
	case "start":
		err := hosting.SendServerAction(operation)
		if err == nil {
			term.Println("Server started!")
		} else {
			term.Println("Error starting server:")
			term.Println(err.Error())
		}
	case "stop":
		err := hosting.SendServerAction(operation)
		if err == nil {
			term.Println("Server stopped!")
		} else {
			term.Println("Error stopping server:")
			term.Println(err.Error())
		}
	case "log", "logs":
		nlines := int64(10)
		if len(args) >= 2 {
			n, err := strconv.ParseInt(args[1], 10, 64)
			if err == nil {
				nlines = n
			}
		}
		log, err := hosting.GetServerLog(nlines)
		if err == nil {
			term.Layout(false)
			term.Dump(log)
		} else {
			term.Println("Error getting server log:")
			term.Println(err.Error())
		}
	default:
		term.Printf("Unknown server operation '%s'\n", operation)
	}
}