-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.js
110 lines (91 loc) · 3.47 KB
/
conf.js
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
105
106
var fs=require('fs');
var path=require('path');
var npmVersion='latest';
var nodeVersion='latest';
var nodeVersionSetting=null;
var npmVersionSetting=null;
var util = require('util');
var path=require('path');
var fs = require('fs');
var sitePath = process.env.DEPLOYMENT_TARGET
var packageJson;
var packageJsonPath = process.env.DEPLOYMENT_TARGET + '\\package.json';
if (path.existsSync(packageJsonPath)) {
packageJson = require(packageJsonPath);
}
else {
packageJson = {};
}
function writeVersions() {
if (process.env.NODE_VERSION != undefined && process.env.NODE_VERSION != null) {
nodeVersionSetting = process.env.NODE_VERSION;
nodeVersion=nodeVersionSetting;
}
if (process.env.NPM_VERSION != undefined && process.env.NPM_VERSION != null) {
npmVersionSetting = process.env.NPM_VERSION;
npmVersion = npmVersionSetting;
}
if (packageJson.engines != undefined) {
var nodeTemp = packageJson.engines.node;
if (nodeVersionSetting==null && nodeTemp != undefined && nodeTemp != null)
nodeVersion = nodeTemp;
var npmTemp = packageJson.engines.npm;
if (npmVersionSetting==null && npmTemp != undefined && npmTemp != null)
npmVersion = npmTemp;
}
var tempBase = process.env.DEPLOYMENT_TARGET + "/../../node/nodist/bin/";
fs.writeFileSync(tempBase + 'nodeVersion.tmp', nodeVersion);
fs.writeFileSync(tempBase + 'npmVersion.tmp', npmVersion);
}
var template="<?xml version=\"1.0\" encoding=\"utf-8\"?> \r\n \
<configuration>\r\n \
<system.webServer> \r\n \
<webSocket enabled=\"false\" /> \r\n \
<handlers> \r\n \
<add name=\"iisnode\" path=\"{NodeStartFile}\" verb=\"*\" modules=\"iisnode\"/> \r\n \
</handlers> \r\n \
<rewrite> \r\n \
<rules> \r\n \
<rule name=\"StaticContent\"> \r\n \
<action type=\"Rewrite\" url=\"public{REQUEST_URI}\"/> \r\n \
</rule> \
<rule name=\"DynamicContent\"> \r\n \
<conditions> \r\n \
<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"True\"/> \r\n \
</conditions> \r\n \
<action type=\"Rewrite\" url=\"{NodeStartFile}\"/> \r\n \
</rule> \r\n \
</rules> \r\n \
</rewrite> \r\n \
<iisnode \r\n \
nodeProcessCommandLine=\""c:\\home\\node\\nodist\\bin\\node.exe"\" \r\n \
debuggingEnabled=\"false\" \r\n \
logDirectory=\"..\\..\\LogFiles\\nodejs\" \r\n \
watchedFiles=\"*.js;iisnode.yml;node_modules\\*;views\\*.jade;views\\*.ejb;routes\\*.js\" /> \r\n \
</system.webServer> \r\n \
</configuration>";
function createIisNodeWebConfigIfNeeded(sitePath) {
// Check if web.config exists in the 'repository', if not generate it in 'wwwroot'
var webConfigPath = path.join(sitePath, 'web.config');
//if (!path.existsSync(webConfigPath)) {
var nodeStartFilePath = getNodeStartFile(sitePath);
if (!nodeStartFilePath) {
console.log('Missing server.js/app.js files, web.config is not generated');
return;
}
var webConfigContent = template.replace(/{NodeStartFile}/g, nodeStartFilePath);
fs.writeFileSync(webConfigPath, webConfigContent, 'utf8');
//}
}
function getNodeStartFile(sitePath) {
var nodeStartFiles = ['server.js', 'app.js'];
for (var i in nodeStartFiles) {
var nodeStartFilePath = path.join(sitePath, nodeStartFiles[i]);
if (path.existsSync(nodeStartFilePath)) {
return nodeStartFiles[i];
}
}
return null;
}
writeVersions();
createIisNodeWebConfigIfNeeded(sitePath);