Skip to content

Commit

Permalink
update iis.ts entry
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 15, 2023
1 parent 0a3a1c0 commit 336278f
Showing 1 changed file with 18 additions and 79 deletions.
97 changes: 18 additions & 79 deletions src/presets/iis.ts
Expand Up @@ -3,85 +3,6 @@ import { writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";

const iisnodeXmlTemplate = () => `
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server\\/debug[\\/]?" />
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
<add segment="node_modules"/>
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode watchedFiles="web.config;*.js" node_env="production" debuggingEnabled="true" />
</system.webServer>
</configuration>
`;

const iisXmlTemplate = () => `
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\\logs\\node.log" startupTimeLimit="20" processPath="C:\\Program Files\\nodejs\\node.exe" arguments=".\\server\\index.mjs">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
`;

// iisnode
export const iisnode = defineNitroPreset({
extends: "node-server",
hooks: {
async compiled(nitro: Nitro) {
await writeFile(
resolve(nitro.options.output.dir, "web.config"),
iisnodeXmlTemplate()
);

await writeFile(
resolve(nitro.options.output.dir, "index.js"),
"import('./server/index.mjs');"
);
},
},
});

// iis directly
export const iis = defineNitroPreset({
extends: "node-server",
hooks: {
Expand All @@ -93,3 +14,21 @@ export const iis = defineNitroPreset({
},

Check warning on line 14 in src/presets/iis.ts

View check run for this annotation

Codecov / codecov/patch

src/presets/iis.ts#L10-L14

Added lines #L10 - L14 were not covered by tests
},
});

function iisXmlTemplate() {
return `<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\\logs\\node.log" startupTimeLimit="20" processPath="C:\\Program Files\\nodejs\\node.exe" arguments=".\\server\\index.mjs">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
`;
}

Check warning on line 34 in src/presets/iis.ts

View check run for this annotation

Codecov / codecov/patch

src/presets/iis.ts#L18-L34

Added lines #L18 - L34 were not covered by tests

0 comments on commit 336278f

Please sign in to comment.