With HttpPlatformHandler you can easily host Nuxt.js web apps on IIS, but changes to your project are required as below,
Nuxt 2.x
The official guide to host Nuxt 2.x for Azure App Service (Windows) shows the general hints,
- Create server\index.js.
- Modify nuxt.config.js.
but it misses important steps,
- You must add
express
and nuxt-start
as dependencies (check your package.json
).
- Change
const nuxt = await loadNuxt(isDev ? 'dev' : 'start')
to simply const nuxt = await loadNuxt('start')
, as isDev
isn’t defined anywhere.
Then your web.config
should look similar to,
<?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=".\node.log" startupTimeLimit="20" processPath="C:\Users\<user name>\AppData\Roaming\nvm\v16.13.2\node.exe" arguments=".\server\index.js">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Note that iisnode mentioned in that Nuxt.js guide is no longer maintained, and only HttpPlatformHandler is recommended.
Note that rewrite rules in official guide were not added as the minimal sample project does not require them, but you can add them for your project if needed.
Nuxt 3.0
The steps are simplified,
npx nuxi init test-nuxt
cd test-nuxt
npm install
npm run build
with web.config
,
<?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=".\node.log" startupTimeLimit="20" processPath="C:\Users\<user name>\AppData\Roaming\nvm\v16.13.2\node.exe" arguments=".output\server\index.mjs">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Reference