How to deploy the Next.js Pages + Middleware template

Preview

The Next.js Pages + Middleware template enables you to quickly deploy a Next.js application with Pages Router, a middleware, and custom configurations.

This template deploys a basic Next.js application containing a domain to access the Single-Page Application (SPA), an Edge Storage configuration, cache settings, Gzip compression, and Rules Engine rules to improve the performance and delivery of static files. Additionally, it creates a new GitHub repository, including a GitHub Action to enable a continuous development workflow and keep your application up to date.

Next.js Pages + Middleware also creates files to implement the Pages Router format, to use a file-system router to map each file to a route. It also includes a middleware that allows you to modify the response for a request and control different aspects of the application, such as performing redirects, setting headers, and others.

This template uses Next version 13.5.6.


To use this template, you must:

  • Generate a GitHub personal token.

You must also activate:

Edge Functions


Application Accelerator

To enable them:

  1. Access Azion Console > Account menu.
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for each module.

To start using this template, access Azion Console and click the + Create button on the homepage.

This will open a modal where you can select Templates > Next.js Pages + Middleware card.


On the template’s page, click the Settings tab to open the configuration form and provide the information to configure your application.

Fields identified with an asterisk are mandatory.

  • Application Name *: the name of your edge application on Azion.
    • Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
  • GitHub Personal Token *: your GitHub personal token.

After completing all the information, click the Next button, located in the bottom-right corner. This will start the deployment process.


You can follow the deployment process through a window showing off the logs. When it’s complete, the deployment page appears, confirming the edge application has been successfully created.

This page shows information about the application and some options to continue your journey.

Now you can manage and adjust the settings through Azion Console.


Considering that this initial setup may not be optimal for your specific edge application, all settings can be customized any time you need through Azion Console.

To manage and edit your edge application’s settings, proceed as follows:

  1. Access Azion Console > Edge Application.
  • You’ll be redirected to the Edge Application page. It lists all the edge applications you’ve created.
  1. Select the edge application related to this template.
  • The list is organized alphabetically. You can also use the search bar located in the upper-left corner of the list; currently, it filters only by Application Name.

After selecting the edge application you’ll work on, you’ll be directed to a page containing all the settings you can configure.

Once the template is deployed, you can also edit and update your args and code, as well as implement a continuous deployment workflow. However, you’ll need first to declare secrets on your project’s GitHub repository to complete the second build with the changes. When the second build is completed, you’ll be able to manage your project with a continuous deployment workflow and edit the args as desired.

To do so, open your new Next.js Pages + Middleware repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:

  1. Add the Azion personal token to the secrets:
Terminal window
AZION_PERSONAL_TOKEN=<value>
  1. Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
main.yml
- name: edge-...
id: azion_edge
...
with:
....
azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }}
....
  1. Open a pull request to merge the changes to the main branch and start the automatic deployment.

Now, your project is ready to work with a continuous deployment workflow, updating instantly any changes in the application or the repository.

The edge application created during the deployment has an assigned Azion domain to make it accessible through the browser. The domain has the following format: xxxxxxxxxx.map.azionedge.net/. However, you can add a custom domain for users to access your edge application through it.

go to configuring a domain guide

Contributors