This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 654
/
NodeSiteEnabler.cs
65 lines (56 loc) · 2.22 KB
/
NodeSiteEnabler.cs
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
using System.IO;
using System.IO.Abstractions;
using Kudu.Core.Infrastructure;
namespace Kudu.Core.Deployment.Generator
{
public static class NodeSiteEnabler
{
private static readonly string[] IisStartupFiles = new[]
{
"default.htm", "default.html", "default.asp", "index.htm", "index.html", "iisstart.htm", "default.aspx", "index.php"
};
private static readonly string[] NodeDetectionFiles = new[] { "package.json" };
private static readonly string[] PotentialNodeDetectionFiles = new[] { "server.js", "app.js" };
public static bool LooksLikeNode(string siteFolder)
{
bool potentiallyLooksLikeNode = false;
// If any of the files in NodeDetectionFiles exist
// We assume it's node.js
foreach (var nodeDetectionFile in NodeDetectionFiles)
{
string fullPath = Path.Combine(siteFolder, nodeDetectionFile);
if (FileSystemHelpers.FileExists(fullPath))
{
return true;
}
}
// If any of the files in PotentialNodeDetectionFiles exist
// We assume it can potentially be node.js
foreach (var nodeDetectionFile in PotentialNodeDetectionFiles)
{
string fullPath = Path.Combine(siteFolder, nodeDetectionFile);
if (FileSystemHelpers.FileExists(fullPath))
{
potentiallyLooksLikeNode = true;
break;
}
}
// If we assume it is potentially a node.js site
if (potentiallyLooksLikeNode)
{
// Check if any of the known iis start pages exist
// If so, then it is not a node.js web site otherwise it is
foreach (var iisStartupFile in IisStartupFiles)
{
string fullPath = Path.Combine(siteFolder, iisStartupFile);
if (FileSystemHelpers.FileExists(fullPath))
{
return false;
}
}
return true;
}
return false;
}
}
}