Created
August 9, 2012 12:58
-
-
Save lanwin/3303989 to your computer and use it in GitHub Desktop.
This patch extens Kudu to use the given app subdomains instead random ports with localhost for site bindings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kudu.SiteManagement/SiteManager.cs | 31 ++++++++++++++++++------------- | |
1 file changed, 18 insertions(+), 13 deletions(-) | |
diff --git a/Kudu.SiteManagement/SiteManager.cs b/Kudu.SiteManagement/SiteManager.cs | |
index 43a6012..87b466d 100644 | |
--- a/Kudu.SiteManagement/SiteManager.cs | |
+++ b/Kudu.SiteManagement/SiteManager.cs | |
@@ -6,12 +6,15 @@ | |
using System.Net.NetworkInformation; | |
using System.Threading; | |
using Kudu.Core.Infrastructure; | |
+using Microsoft.Web.Administration; | |
using IIS = Microsoft.Web.Administration; | |
namespace Kudu.SiteManagement | |
{ | |
public class SiteManager : ISiteManager | |
{ | |
+ const string BaseHost = "kudu.local"; | |
+ | |
private static Random portNumberGenRnd = new Random((int)DateTime.Now.Ticks); | |
private readonly IPathResolver _pathResolver; | |
@@ -94,7 +97,7 @@ public Site CreateSite(string applicationName) | |
{ | |
// Create the service site for this site | |
string serviceSiteName = GetServiceSite(applicationName); | |
- int serviceSitePort = CreateSite(iis, applicationName, serviceSiteName, _pathResolver.ServiceSitePath); | |
+ string serviceUrl = CreateSite(iis, applicationName, serviceSiteName, _pathResolver.ServiceSitePath); | |
// Create the main site | |
string siteName = GetLiveSite(applicationName); | |
@@ -115,7 +118,7 @@ public Site CreateSite(string applicationName) | |
</body> | |
</html>"); | |
- int sitePort = CreateSite(iis, applicationName, siteName, webRoot); | |
+ string siteUrl = CreateSite(iis, applicationName, siteName, webRoot, 80); | |
// Map a path called app to the site root under the service site | |
MapServiceSitePath(iis, applicationName, Constants.MappedLiveSite, siteRoot); | |
@@ -129,8 +132,8 @@ public Site CreateSite(string applicationName) | |
return new Site | |
{ | |
- ServiceUrl = String.Format("http://localhost:{0}/", serviceSitePort), | |
- SiteUrl = String.Format("http://localhost:{0}/", sitePort), | |
+ ServiceUrl = serviceUrl, | |
+ SiteUrl = siteUrl, | |
}; | |
} | |
catch | |
@@ -152,7 +155,7 @@ public bool TryCreateDeveloperSite(string applicationName, out string siteUrl) | |
// Get the path to the dev site | |
string siteRoot = _pathResolver.GetDeveloperApplicationPath(applicationName); | |
string webRoot = Path.Combine(siteRoot, Constants.WebRoot); | |
- int sitePort = CreateSite(iis, applicationName, devSiteName, webRoot); | |
+ siteUrl = CreateSite(iis, applicationName, devSiteName, webRoot); | |
// Ensure the directory is created | |
FileSystemHelpers.EnsureDirectory(webRoot); | |
@@ -162,12 +165,11 @@ public bool TryCreateDeveloperSite(string applicationName, out string siteUrl) | |
iis.CommitChanges(); | |
- | |
- siteUrl = String.Format("http://localhost:{0}/", sitePort); | |
return true; | |
} | |
- siteUrl = String.Format("http://localhost:{0}/", site.Bindings[0].EndPoint.Port); | |
+ var host = applicationName + "." + BaseHost; | |
+ siteUrl = String.Format("http://{0}:{1}/", host, site.Bindings[0].EndPoint.Port); | |
return false; | |
} | |
@@ -390,12 +392,15 @@ private bool IsAvailable(int port, IIS.ServerManager iis) | |
return true; | |
} | |
- private int CreateSite(IIS.ServerManager iis, string applicationName, string siteName, string siteRoot) | |
+ private string CreateSite(ServerManager iis, string applicationName, string siteName, string siteRoot, int sitePort = -1) | |
{ | |
var pool = EnsureAppPool(iis, applicationName); | |
- int sitePort = GetRandomPort(iis); | |
- var site = iis.Sites.Add(siteName, siteRoot, sitePort); | |
+ if(sitePort<=0) | |
+ sitePort = GetRandomPort(iis); | |
+ | |
+ var host = applicationName + "." + BaseHost; | |
+ var site = iis.Sites.Add(siteName, "http", "*:" + sitePort + ":" + host, siteRoot); | |
site.ApplicationDefaults.ApplicationPoolName = pool.Name; | |
if (_traceFailedRequests) | |
@@ -406,7 +411,7 @@ private int CreateSite(IIS.ServerManager iis, string applicationName, string sit | |
site.TraceFailedRequestsLogging.Directory = path; | |
} | |
- return sitePort; | |
+ return String.Format("http://{0}:{1}/", host, sitePort); | |
} | |
private void DeleteSite(IIS.ServerManager iis, string siteName, bool deletePhysicalFiles = true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment