-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
976ec35
commit e87e2ba
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters