RestroPRO SaaS DocsInstallationDeploy Backend

Step 6: Deploy Your Backend Application

Video Guide


6.1 Create a New App

  • In the dashboard, click on Apps in the left menu.
  • Click on the Create New App button.
  • Enter a name for your app (e.g., backend) and click Create New App.
  • Ensure you select the option for persistent data.

image

6.2 Setup .env file in App Config

  • Configure Your Environment Variables: Each environment variable defines specific settings for your app. Here’s a general breakdown of the important variables and how they might change based on your app’s domain:
6.2.1 Database URL
  • This URL connects your app to the database. It typically includes the database type (mysql in our case), username, password, host, port, and database name.
DATABASE_URL='mysql://[username]:[password]@[host]:[port]/[database_name]'

Replace the host, password as per configured in new app created. We get the host in HTTP Settings of the created DB (mysql-db) app as shown.

image

Eg :

DATABASE_URL='mysql://root:YOURPASSWORD@srv-captain--mysql-db-db:3306/restropro_saas'
6.2.2 Jwt Secret
  • The JWT_SECRET is used to sign JSON Web Tokens (JWT) for authentication. Set this value as a secure, unique string to ensure the safety of your app
  • These values define your frontend’s URL and its cookie domain. Update these according to the domain name where your frontend is hosted. For example: If frontend is hosted on https://yourdomain.com, the cookie value will be yourdomain.com.
FRONTEND_DOMAIN="https://yourdomain.com"
FRONTEND_DOMAIN_COOKIE=".yourdomain.com"
💡

If you’re planning to host your frontend app on a subdomain, such as app.example.com, make sure to set the FRONTEND_DOMAIN_COOKIE value to .example.com. The leading dot (.) is intentional, as it allows the subdomain to access the cookie. An incorrect configuration can lead to login issues.

6.2.5 SMTP Credentials
  • These values configure email sending. Adjust them based on your SMTP provider. Update the host, port, username, and password to match your email service.

Sample .env

DATABASE_URL=mysql://root:thisismypassword@srv-captain--mysql-db-db:3306/restropro_saas
JWT_SECRET=SECRET
JWT_EXPIRY=15m
JWT_EXPIRY_REFRESH=30d
COOKIE_EXPIRY=300000
COOKIE_EXPIRY_REFRESH=2592000000
PASSWORD_SALT=10
FRONTEND_DOMAIN=https://yourdomain.com
FRONTEND_DOMAIN_COOKIE=yourdomain.com
SMTP_HOST=sandbox.smtp.mailtrap.io
SMTP_PORT=2525
SMTP_EMAIL=4d049cab28855f
SMTP_PASSWORD=d388ajdsb2ddfae7
ENCRYPTION_KEY=uiflow
  • Navigate to the App Configs section of your newly created app.
  • Paste the contents of your .env file into the environmental variables section using Bulk Edit option
  • ensure all environment variables are set correctly.

App Configs Section

  • Also add the persistent directory as shown

image

6.3 Connect New Domain in HTTP Settings

  • Navigate to the HTTP Settings section.
  • Enter your custom domain (e.g., backend.yourdomain.com) and click on Connect New Domain.
  • Ensure to enable HTTPS for secure communication.
  • Select the option for Force Https & WebSocket Support to allow real-time communication.

image

6.4 CapRover Deploy

Here are two convenient methods for deploying your application to CapRover: Drag & Drop, which allows for quick uploads, and Git, which enables seamless version control integration. Choose the method that best fits your workflow. However caprover supports more methods of deployments, you can explore more at here.

6.4.1 Method 1: Drag & Drop

Package Your Application

  • Open the terminal preferably Git Bash. Navigate to where your backend folder is located.
  • Create a tarball (.tar) containing the source code and necessary files for deployment (e.g., Dockerfile, app files, etc.) using the below command.
tar -cvf ./deploy.tar --exclude='.map' --exclude='node_modules' --exclude='.git' ./captain-definition ./
  • A new file deploy.tar will be created in the same directory. This is the file to be uploaded for deployment.

image

Drag & Drop to deploy

  • Go the deployments & Scroll to Tarball section. image

  • Simply drag your generated file deploy.tar into the “Upload & Deploy” section of the app page. image

  • CapRover will handle the deployment process based on your uploaded package.

6.4.2 Method 2: Using Git

This method uses git to deploy your backend application to CapRover with the latest changes from your selected branch.

  • Open your terminal preferably Git Bash and navigate to the backend folder where your Git repository is configured.

  • Make sure to select the appropriate branch (e.g., main) that you want to push changes from.

  • Run the following command to deploy your application:

    caprover deploy
  • On Success, you will get this output. image


🎉

Congratulations! Your backend application has been successfully deployed on CapRover and is ready to handle requests. Enjoy building and scaling your application with ease!