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.4 Stripe Credentials
  • To configure subscriptions for the app, follow the mentioned steps & then get your stripe credentails - STRIPE_SECRET & STRIPE_WEBHOOK_SECRET as required.
6.2.4.1 Stripe Subscription Setup
  • Goto Stripe and set up your account according to your business registration type. Once you activate your account, follow the given procedure.
  • Goto Stripe Dashboard and Select “Product catalogue”, then Add new product. image
  • Fill the details as per your business requirements. image
  • Once you create the Subscription Product, you will see it like this. image
  • Now go back to Stripe Dashboard and open the developers page, you will get API keys from there. Look for a secret key, and copy it. This will be your STRIPE_SECRET. image
  • Now we will set up the webhook. For that open Stripe Dashboard and goto developers page again. Goto Webhooks Tab, then click on Add endpoint. image
  • Then provide the webhook URL, this will be our backend route webhook handler, so we’re yet to setup the backend, so you just need to provide the url. For example if i’m setting Backend on domain “api.example.com” then the webhook URL will look like this.Webhook URL: https://api.example.com/api/v1/auth/stripe-webhook. Replace the domain, to your backend domain. After placing endpoint URL, click on the ‘select events to listen to’ image
  • Look for the following events and select them. image
  • Once you add it open the created webhook endpoint in Stripe Dashboard.
  • Click on the ‘Reveal’ to copy the Webhook Signing Secret. image
  • Paste the copied secret in STRIPE_WEBHOOK_SECRET
STRIPE_SECRET=YOUR_STRIPE_SECRET
STRIPE_WEBHOOK_SECRET=YOUR_STRIPE_WEBHOOK_SECRET
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
STRIPE_SECRET=sk_live_51PFbvQSCWiCS3BjbcjbcjoWGPCZkgLEmtRksfOoTpbRwPQ0H84OrD0r000QNu0Zkm
STRIPE_WEBHOOK_SECRET=whsec_nqjVQsMQP7PHshrWbkTbdjsbjvhZWl33W85sWaMz
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!