Search code examples
node.jsazureastrojsazure-static-web-app

How do I deploy an Astro SSR site with a NodeJS adapter to Azure Static Web Apps?


I'm trying to deploy a minimal server-side rendered Astro site to Azure Static Web Apps. It uses the NodeJS adapter:

import { defineConfig } from "astro/config";
import nodejs from "@astrojs/node";
import svelte from "@astrojs/svelte";

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
  alias: {
    "@": "./src"
  },
  root: ".",
  trailingSlash: "never",
  output: "server",
  adapter: node({
    mode: "standalone"
  }),
  integrations: [svelte()]
});

The deployment runs on commit using a GitHub action, but the action fails with this error:

---End of Oryx build logs---
Try to validate location at: '/bin/staticsites/177edecb-f124-4e6e-a04d-0d27e37f1945-swa-oryx/app/dist'.
Finished building app with Oryx
Detected serverRenderFramework: StaticWebApp
Failed to find a default file in the app artifacts folder (dist). Valid default files: index.html,Index.html.
If your application contains purely static content, please verify that the variable 'app_location' in your workflow file points to the root of your application.
If your application requires build steps, please validate that a default file exists in the build output directory.

There is no index.html in the dist/client directory that is generated by running npm run build.


Solution

  • Unfortunately what you are looking for is not possible with Azure static web apps as they do not support SSR, only static builds.

    You have set output in your config to server rather than static, it is this that causes no index.html to be created as it assumes it will be done at run time hence the error.

    'server' - Building an app to be deployed to a host supporting SSR (server-side rendering).

    From: https://docs.astro.build/en/reference/configuration-reference/#output

    I have run an Astro static built on Azure Static Web Apps and it works well. You may want to think if you need SSR. Azure Static Web Apps work well with Azure functions for APIs and code needed to run on a server.

    If you want to do SSR you need to look at hosting using another mechanism such as an Azure App service plan or Azure Continer Apps though this will be more expensive.