Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iis): improve preset and docs #1784

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions docs/content/2.deploy/providers/iis.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ Deploy Nitro apps to IIS.
This is an experimental preset.
::

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

**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.
1. Install the latest LTS version of [Node.js](https://nodejs.org/en/) on your Windows Server.
1. Install [IISnode](https://github.com/azure/iisnode/releases)
2. Install [IIS `URLRewrite` Module](https://www.iis.net/downloads/microsoft/url-rewrite).
3. In IIS, add `.mjs` as a new mime type and set its content type to `application/javascript`.
4. Deploy the contents of your `.output` folder to your website in IIS.

## Using IIS directly
## Using IIS Handler

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

If you do not wish to use IISnode, you can use IIS directly.
You can use IIS http handler 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.
1. Install the latest LTS version of [Node.js](https://nodejs.org/en/) on your Windows Server.
2. Install [IIS `HttpPlatformHandler` Module](https://www.iis.net/downloads/microsoft/httpplatformhandler)
3. Copy your `.output` directory into the Windows Server, and create a website on IIS pointing to that exact directory.

## IIS Config options
Expand Down
106 changes: 66 additions & 40 deletions src/presets/iis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolveFile, writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";

export const iis = defineNitroPreset({
export const iisHandler = defineNitroPreset({
extends: "node-server",
hooks: {
async compiled(nitro: Nitro) {
Expand All @@ -16,6 +16,8 @@ export const iis = defineNitroPreset({
},
});

export const iis = iisHandler;

export const iisNode = defineNitroPreset({
extends: "node-server",
hooks: {
Expand All @@ -42,45 +44,69 @@ export const iisNode = defineNitroPreset({
async function iisnodeXmlTemplate(nitro: Nitro) {
const path = resolveFile("web.config", nitro.options.rootDir, ["config"]);
const originalString = `<?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>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:
https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the index.js file is a Node.js site to be handled by the iisnode module -->
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^index.js/debug[/]?" />
</rule>

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{PATH_INFO}" />
</rule>

<!-- All other URLs are mapped to the Node.js site entrypoint -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>

<!-- 'bin' directory has no special meaning in Node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>

<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />

<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<iisnode
watchedFiles="index.js"
node_env="production"
debuggingEnabled="false"
loggingEnabled="false"
/>
</system.webServer>
</configuration>
`;
if (path !== undefined) {
const fileString = await readFile(path, "utf8");
Expand Down
2 changes: 1 addition & 1 deletion src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export * from "./cleavr";
export * from "./layer0";
export * from "./flightcontrol";
export * from "./lagon";
export { iis, iisNode } from "./iis";
export { iis, iisHandler, iisNode } from "./iis";
export { _static as static } from "./static";
export * from "./github-pages";