title: Deploying Next.js to Azure SWA with serverless functions
body: <p>I'm trying to deploy a Next.js Static Web App to Azure, that uses serverless functions for API routes (Auth, SSR, etc). I followed this guide: <a href="https://docs.microsoft.com/en-us/azure/static-web-apps/deploy-nextjs" rel="noreferrer">https://docs.microsoft.com/en-us/azure/static-web-apps/deploy-nextjs</a>. There's a <a href="https://docs.microsoft.com/en-us/azure/static-web-apps/add-api" rel="noreferrer">general guide for adding APIs to Azure SWAs</a> but I haven't been able to apply that to my Next.js app.</p>
  <p>Next.js has a config option to set serverless apps as the build target.</p>
  <pre><code>module.exports = {
    target: 'serverless',
  }
  </code></pre>
  <p>What I imagine I would essentially need is a postbuild step that could convert the build output for the api functions into a format that Azure understands. This would run during the GitHub Action build and deploy step.</p>
  <p>There's a node module that does this for Netlify, <a href="https://github.com/netlify/next-on-netlify" rel="noreferrer">https://github.com/netlify/next-on-netlify</a> but the build output isn't directly compatible with Azure. There's also <a href="https://www.serverless.com/plugins/serverless-nextjs-plugin" rel="noreferrer">this for AWS Serverless</a>.</p>
  <p>Has anyone had any luck with this sort of setup on Azure?</p>