Add support for setting alias when creatign instance. (#140)
* Add support for setting alias when creatign instance. The POST to create a instance now provides an `alias` field which then can be used to access the instance services through the following URL: `http://<alias>-<short_session>-<port>.<tld>` When creating a session you can now send an `alias` * Remove unnecessary function * Add alias support for DNS resolution
This commit is contained in:
@@ -11,11 +11,14 @@ import (
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/play-with-docker/play-with-docker/config"
|
||||
"github.com/play-with-docker/play-with-docker/services"
|
||||
)
|
||||
|
||||
func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
|
||||
node := vars["node"]
|
||||
port := vars["port"]
|
||||
alias := vars["alias"]
|
||||
sessionPrefix := vars["session"]
|
||||
hostPort := strings.Split(req.Host, ":")
|
||||
|
||||
// give priority to the URL host port
|
||||
@@ -25,6 +28,14 @@ func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
|
||||
port = "80"
|
||||
}
|
||||
|
||||
if alias != "" {
|
||||
instance := services.FindInstanceByAlias(sessionPrefix, alias)
|
||||
if instance != nil {
|
||||
node = instance.IP
|
||||
return node, port
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(node, "pwd") {
|
||||
// Node is actually an ip, need to convert underscores by dots.
|
||||
ip := strings.Replace(strings.TrimPrefix(node, "pwd"), "_", ".", -1)
|
||||
|
||||
Reference in New Issue
Block a user