Skip to content

Commit

Permalink
feat: add iis server preset (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-k1208 authored Jul 15, 2023
1 parent 976ec35 commit e87e2ba
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/content/2.deploy/providers/iis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# IIS

Deploy Nitro apps to IIS.

::alert{type="warning"}
This is an experimental preset.
::

## Using [IISnode](https://github.com/Azure/iisnode) (recommended)

**Preset:** `iis-node` ([switch to this preset](/deploy/#changing-the-deployment-preset))

1. Install [IISnode](https://github.com/azure/iisnode/releases), and the [IIS URL Rewrite Module](https://www.iis.net/downloads/microsoft/url-rewrite).
2. In IIS, add `.mjs` as a new mime type and set its content type to `application/javascript`.
3. Deploy the contents of your `.output` folder to your website in IIS.


## Using IIS directly

**Preset:** `iis-handler` ([switch to this preset](/deploy/#changing-the-deployment-preset))

If you do not wish to use IISnode, you can use IIS directly.

1. Make sure that [Node.js](https://nodejs.org/en/) is installed on your Windows Server.
2. Make sure [`HttpPlatformHandler` Module](https://www.iis.net/downloads/microsoft/httpplatformhandler) is installed.
3. Copy your `.output` directory into the Windows Server, and create a website on IIS pointing to that exact directory.
65 changes: 65 additions & 0 deletions src/presets/iis-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { resolve } from "pathe";
import { writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";

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');"
);
},
},
});

function iisnodeXmlTemplate() {
return `<?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>
`;
}
34 changes: 34 additions & 0 deletions src/presets/iis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { resolve } from "pathe";
import { writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";

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

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>
`;
}
2 changes: 2 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export * from "./cleavr";
export * from "./layer0";
export * from "./flightcontrol";
export * from "./lagon";
export * from "./iis-node";
export * from "./iis";
export { _static as static } from "./static";
export * from "./github-pages";

0 comments on commit e87e2ba

Please sign in to comment.