Building the Ticketing App with Next.js, Vercel and Back4App
In this tutorial, we'll build a Ticketing System using Next.js with the app router, Back4App as the backend service, and Tailwind CSS for styling. The app allows users to create, update, view, and delete tickets, while utilizing Parse Server on Back4App for database management.
Before starting, make sure you have:
- Log in to your Back4App dashboard and create a new project.
- Navigate to the Data Browser and create a new class called Ticket with the following schema:
Field Name | Type |
---|---|
title | String |
description | String |
category | String |
priority | Number |
progress | Number |
status | String |
createdAt | Date (auto-generated) |
updatedAt | Date (auto-generated) |
Run the following command to create a new Next.js project:
Install Tailwind CSS, Font Awesome, and Parse SDK for backend operations:
Edit the tailwind.config.js file to configure the Tailwind CSS content paths:
In styles/globals.css, add the Tailwind imports:
Following the structure provided, create the necessary directories and components.
Directory Structure:
In the /lib folder, create a parseClient.js file to configure the Parse SDK.
Replace 'YOUR_APP_ID' and 'YOUR_JS_KEY' with your Back4App project credentials.
This component will handle both creating and updating tickets.
In /components/TicketForm.jsx, create the following:
This component will display individual ticket information.
In /components/TicketCard.jsx:
A confirmation component for deleting tickets:
In /components/DeleteBlock.jsx:
This component shows the progress as a percentage bar:
In /components/ProgressDisplay.jsx:
In /app/page.js, display the list of tickets:
In /app/tickets/[id]/page.js:
- You can sign up with GitHub, GitLab, or Bitbucket. Vercel makes it easy to link your repository directly for deployments.
- To deploy your app on Vercel, you need to have your project hosted on a version control platform like GitHub (or GitLab/Bitbucket).
If your project is not yet on GitHub, follow these steps:
- Initialize git in your project directory:
- Add your project to GitHub:
If you prefer deploying directly from the command line, install the Vercel CLI globally:
Alternatively, you can deploy via Vercel's dashboard, which we’ll cover next.
- Click New Project.
- Choose the Git repository that contains your Next.js project.
- Configure your project:
- Vercel will automatically detect that it's a Next.js project and apply the correct build settings.
- Set the Root Directory to the project’s folder (if necessary).
You’ll need to configure your Back4App credentials and any other environment variables in Vercel.
- In Vercel's Project Settings, go to the Environment Variables section.
- Add the following environment variables:
If you use local environment variables during development, make sure to create a .env.local file in your root project directory with the following variables:
These environment variables will also be used by Vercel once they are set in the Vercel dashboard.
- Ensure that Node.js version and build command are correctly configured (Vercel auto-detects this).
- For Next.js apps, the default settings should be:
- Build command: npm run build
- Output directory: .next/
- After you link your GitHub repository, Vercel will automatically trigger a build and deployment process.
- You can view the status of your build in the Vercel dashboard.
If any issues arise during the deployment, you can inspect the deployment logs to debug them.
Once the deployment is successful, Vercel will provide you with a unique URL where your Next.js app is live. You can visit the URL to access your deployed Ticketing App.
For example: https://your-app-name.vercel.app/
- Back4App credentials: Double-check that your Back4App environment variables are correctly set in both .env.local (for local development) and the Vercel dashboard (for production).
- CORS (Cross-Origin Resource Sharing): Make sure that Back4App allows your Vercel URL in its CORS settings, which you can configure in the Back4App dashboard under Security.
- Test your API: Before deploying, test your Back4App API interactions locally to ensure everything works smoothly.
With these steps, your Next.js Ticketing App should now be deployed on Vercel, using Back4App for the backend. This completes the full development cycle, from setting up Back4App, creating the frontend in Next.js, to deploying the app live on Vercel.
If you want to make updates, simply push changes to your GitHub repository, and Vercel will automatically trigger a new deployment.