- Welcome to Azion Docs
- Guides
- How to Build and Publish a Next.js Project with SSR on the Azion Platform
How to Build and Publish a Next.js Project with Server-side Rendering (SSR) on the Azion Platform
Next.js and Server-side Rendering (SSR)
Next.js, a flexible framework based on the React library, provides powerful tools for building fast applications.
SSR generates HTML for each request, offering several benefits, including:
- Improved initial loading performance.
- Search engine optimization (SEO).
- Social media sharing.
- Enhanced user experience.
- Accessibility and compatibility.
- Code sharing and performance optimizations.
Next.js SSR Project on the Azion Platform
Requirements
Before getting started, make sure you have:
- An Azion platform account with Edge Functions enabled.
- Node.js runtime environment (version 16.x or 18.x) installed in your build environment.
- The latest version of Azion CLI installed.
- Next.js installed.
To install Azion CLI, visit the Installing Azion CLI manually page.
Note: currently, the supported Next.js version is
12
.
Setting up the Project
- Create a new folder for your project:
mkdir next-js-azion
- Access the project folder:
cd next-js-azion
- Inside the project folder, use the following command to create a Next.js project:
npx create-next-app@12 azion-next-ssr && cd azion-next-ssr && npm i next@12
- Open the project directory in your preferred code editor, such as VSCode:
code .
Configuring Next.js for Azion
- Open the
next.config.js
file in your project’s root directory. - Add the
experimental
object inside thenextConfig
constant:
const nextConfig = {
experimental: {
runtime: 'experimental-edge',
},
reactStrictMode: true,
swcMinify: true,
}
module.exports = nextConfig
Building and Publishing the application on the Azion Platform
- In the terminal, in your project’s root directory, initialize the Azion Edge Application:
azioncli edge_applications init
- Run the
build
command:
azioncli edge_applications build
- Publish the application:
azioncli edge_applications publish
After running the publish
command, you’ll receive a domain for accessing your SSR Next.js project on the Azion Platform.
Wait a few minutes so the propagation takes place, and then access your application using the provided domain, that should be similar to:
https://ala5yasjasdsa0pnm.map.azionedge.net
Didn’t find what you were looking for? Open a ticket.