Server side app
A NextJS application for Navbar deployed to Vercel
In this article, we will go through a process of creating a brand new NextJS application for Navbar, that will be hosted on Vercel.
Create a webapp project
Creating NextJS project
Let's give our project a name - this name does not affect much, but keep it simple and do not include special characters in there, as this name will be referenced in
manifest.json
file later automatically. I will call itsuper-cool-app
Choose whatever NextJS setup options you would like to use, those do not affect the boilerplate at all. I chose: - Yes to TypeScript (all the way) - No to ESLint - Yes to TailwindCSS - Yes to using
/src
directory - Yes to usingApp Router
- No to customizingimport alias
Install the packages required by NextJS
Alias scripts to manage NextJS project
You don't want to every time go inside /packages/super-cool-app
to start the dev server. It is more convenient to do so from the root of your entire boilerplate, like 2 demo applications are showcasing. Let's do the same!
In the root folder of the boilerplate (attention, not our new NextJS project, but 2 levels up), open package.json
file and add following to the scripts
property:
Here, the parameters of scripts/run.mjs
receives a name of the package to be launched, which is a name of our newly created NextJS package.
While we are at it, let's also add a build script. Even though it is NOT required for server side apps, but I recommend keeping it for the sake of completeness, boilerplate will handle the rest for you.
Modify the build
script to add the following:
Here, scripts/build.mjs
receives an environment to build the app for (production a.k.a prod) and a name of the package. If you have multiple apps / packages, just list them here without commas.
Let's verify that everything works as expected! In the root directory, where we modified the package.json
file, let's start up our NextJS package:
If everything was done correctly, you can see the following log:
Create a zaf.config.json file
Now, let's make this project recognisable by boilerplate, so that we can see it in our Zendesk instance.
In the root of your newly created project (I will refer to it as super-cool-app
in my case), create zaf.config.json
file.
Open it (or your entire boilerplate project) in your code editor (I use vim btw) and add the following content:
We don't have a production url yet (our application is not deployed) but we already know, when we launch our NextJS project for local development, we use http://localhost
as url and port 3000
(see screenshot from Alias scripts to manage NextJS project section).
If your NextJS project runs on a different url and port - update them in this file.
Last command to run, is to create a zcli
server that will establish connection between our application and Zendesk:
That's all it takes get a basic version of server side app running in your zendesk instance. Now, you can verify that everything works by visting your Zendesk ticketing instance, and do not forget to append ?zcli_apps=true
to the end of the url.
On the left side you will notice a small icon that is our application entry point:
Once opened, you should be greeted with default NextJS page.
Add zafClient
We have our basic application, you are free to do whatever you want, but you will probably want to interact with Zendesk ZAF SDK (Zendesk Applications Framework).
To do so, we need to inject a script into the main page of NextJS. This step is slightly different than it is in bundled apps, because we don't use Vite as our bundler.
This step will be slightly different to each project based on a tech stack, I trust you knowing how to add scripts to your application (Nuxt, SvelteKit etc).
In our case of NextJS app, I will add this to src/page.tsx:
zafClient types for additional typesafety
To get types autocomplte for zafClient
(which will allow you to fetch data in a type-safe manner), adjust your tsconfig.json
file with following properties:
And change moduleResolution
to node:
That's it, if all done correctly, when opening NextJS application now, you can see in the browser log
Publish your application
Now, whenever you will use yarn build
command, the output of /dist
folder will point to vercel-deployed application, instead of your local dev environment (localhost).
Get in touch
Last updated
Was this helpful?