unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.58k stars 481 forks source link

Azure App Service preset #2231

Open danielroe opened 4 months ago

danielroe commented 4 months ago

It would be nice to have a built-in azure app service provider (see https://github.com/nuxt/nuxt/issues/26140).

I haven't validated yet whether this is possible, so this is just a tracker.

dombarnes commented 3 weeks ago

with ssr: false and nitro: { preset: 'static' } I have a custom web.config to be able to run on Azure App Service (Integrated Pipeline)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- To customize the asp.net core module uncomment and edit the following section.
    For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
    <system.webServer>
      <webSocket enabled="false" />
      <httpProtocol>
        <customHeaders>
          <clear />
          <remove name="x-powered-by" />
          <remove name="server" />
          <remove name="Cache-Control" />
          <add name="Cache-Control" value="public, max-age=31536000" />
          <add name="Pragma" value="no-cache" />
        </customHeaders>
      </httpProtocol>
      <staticContent>
        <mimeMap fileExtension=".js" mimeType="application/javascript" />
        <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
        <mimeMap fileExtension=".json" mimeType="application/json" />
        <mimeMap fileExtension=".otf" mimeType="font/otf" />
        <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
        <mimeMap fileExtension=".js.gz" mimeType="application/javascript" />
        <mimeMap fileExtension=".dat.gz" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".dll.gz" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".json.gz" mimeType="application/json" />
        <mimeMap fileExtension=".wasm.gz" mimeType="application/wasm" />
        <mimeMap fileExtension=".blat.gz" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".html.gz" mimeType="text/html" />
        <mimeMap fileExtension=".css.gz" mimeType="text/css" />
        <mimeMap fileExtension=".ico.gz" mimeType="image/x-icon" />
        <mimeMap fileExtension=".svg.gz" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".js.br" mimeType="application/javascript" />
        <mimeMap fileExtension=".dat.br" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".dll.br" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".json.br" mimeType="application/json" />
        <mimeMap fileExtension=".wasm.br" mimeType="application/wasm" />
        <mimeMap fileExtension=".blat.br" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".html.br" mimeType="text/html" />
        <mimeMap fileExtension=".css.br" mimeType="text/css" />
        <mimeMap fileExtension=".ico.br" mimeType="image/x-icon" />
        <mimeMap fileExtension=".svg.br" mimeType="image/svg+xml" />
      </staticContent>
      <modules runAllManagedModulesForAllRequests="true"/>
      <rewrite>
        <rules>
          <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
          <rule name="StaticContent">
            <action type="Rewrite" url="{PATH_INFO}" />
          </rule>
          <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <!-- Because each path is generated in a folder, this breaks the site -->
              <!-- <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> -->
            </conditions>
            <action type="Rewrite" url="index.html" />
          </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.html" />
          </rule>
        </rules>
      </rewrite>
      <!-- Make sure error responses are left untouched -->
      <httpErrors existingResponse="PassThrough" />
    </system.webServer>
  </configuration>

If I toggle ssr: true, it doesn't seem to work, just rewrites all paths back to /. I am by no means any expert on IIS!