How to deploy the Next.js App + Configurations + Turso template
Preview
The Next.js App + Configurations + Turso template provides a quick start to build a Next.js application with custom configurations, App Router, and integration with a Turso Database.
This template uses Next version 13.5.6
and LibSQL 0.5.3
.
Requirements
Section titled RequirementsTo use this template, you must:
- Create a Turso account.
- Install the Turso CLI.
- Create a database with a table called
posts
, with the fieldsid
andmessage
, as explained in the next section. - Generate your GitHub personal token.
You must also activate:
To enable them:
- Access Azion Console > Account menu.
- Select the Billing & Subscriptions option.
- Select the Subscriptions tab.
- Activate the switch for each module.
Creating a Turso database
Section titled Creating a Turso databaseAssuming you’ve already created a Turso account and installed the Turso CLI on your computer, you’ll just need to complete the following steps using a few commands:
- Authenticate your Turso account:
turso login
- Create a new database:
turso db create
- List your databases:
turso db list
- You’ll obtain the LibSQL URL for your database.
- Create an authorization token to access it:
turso db tokens create [your database name]
- In this case, the name for your database should be
posts
. - Remember to save it in a secure place.
- In this case, the name for your database should be
- Open the shell interface of your database:
turso db shell [your database name]
- Create the table that’ll be used by this template using SQL:
If you’ve run all the commands correctly, you’ll be able to use the URL/token during the launch process of this template.
Getting the template
Section titled Getting the templateTo 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 App + Configurations + Turso card.
Setting up the template
Section titled Setting up the templateOn 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.
- GitHub Personal Token *: your GitHub personal token.
- Turso Database URL *: the LibSQL URL to connect with your Turso database.
- Turso Authorization Token *: the authorization token to access your Turso database.
After completing all the information, click the Next button, located in the bottom-right corner. This will start the deployment process.
Deploying the template
Section titled Deploying the templateYou 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.
Key configurations
Section titled Key configurationsThis template deploys a basic Next.js application containing a domain to access the Single-Page Application (SPA) and demonstrate the integration under the /turso
route, as well as Edge Storage configuration, cache settings, Gzip compression, and Rules Engine rules to improve the performance and delivery of static files.
It creates a new GitHub repository, including a GitHub Action to enable a continuous development workflow and keep your application up to date.
Additionally, Next.js App + Configurations creates files to implement the App Router format, including the index page, edge API routing, and Custom Route Handlers, in the new repository during the deployment.
This template also provides a basic CRUD example of how to integrate a Next.js application with a Turso Database and delivers an API route /api/posts
, which enables Turso’s LibSQL SDK to connect to the database to create, read, update, and delete items.
Managing the template
Section titled Managing the templateConsidering 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:
- Access Azion Console > Edge Application.
- You’ll be redirected to the Edge Application page. It lists all the edge applications you’ve created.
- 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.
Continuous deployment
Section titled Continuous deploymentOnce 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 [NAME] repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:
- Add the Azion personal token to the secrets:
- Read how to generate an Azion personal token in the documentation.
- Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
- 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.
Adding a custom domain
Section titled Adding a custom domainThe 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.
Contributors