public
Last active

This patch extens Kudu to use the given app subdomains instead random ports with localhost for site bindings.

  • Download Gist
kudu_with_subdomain.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.