Build & Deploy Production Ready MedusaJS Shop

3 min read 6 months ago
Published on Jun 30, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Tutorial: Building & Deploying a Production-Ready MedusaJS Shop

Step 1: Set Up Development Environment

  1. Install Node.js, Git, and PostgreSQL on your machine.
  2. Clone the Medusa server and storefront repositories to your local machine.
  3. Install dependencies by running the necessary commands.
  4. Configure the backend and necessary plugins.

Step 2: Initialize and Commit Code to GitHub

  1. Initialize Git and commit the code to your GitHub repository for both the backend and frontend folders.
  2. Push the code to your GitHub repository.

Step 3: Prepare Backend for Deployment

  1. Create a PostgreSQL database and a cluster on Digital Ocean.
  2. Modify startup commands in the package.json file and database connection strings in the Medusa config file.
  3. Make changes to the .gitignore file to ensure sensitive files are not committed.
  4. Commit the changes to your GitHub repository.

Step 4: Create App Hosting on Digital Ocean

  1. Connect your GitHub repository to Digital Ocean.
  2. Configure app settings such as RAM, auto-scaling, and port.
  3. Add project configuration modules and environmental variables.
  4. Deploy the app on Digital Ocean.

Step 5: Attach Resources to the App

  1. Attach the PostgreSQL database and Redis to the app.
  2. Configure environmental variables by referencing the database names and URLs.

Step 6: Create Admin User and Configure Storefront

  1. Create an admin user by connecting to the database from your local machine.
  2. Set up regions for your store.
  3. Prepare the storefront for deployment on Vercel.
  4. Deploy the storefront on Vercel.

Step 7: Add Plugins to the Store

  1. Enable product search using Meilisearch.
  2. Configure Meilisearch in the Medusa config file and add it to the list of plugins.
  3. Add necessary configurations to the Next.js storefront template.

Step 8: Configure Payment and Transactional Emails

  1. Install and configure the Stripe plugin in Medusa for payments.
  2. Set up Stripe endpoints and add necessary environmental variables.
  3. Install and configure the SendGrid plugin for transactional emails.
  4. Create dynamic email templates for order confirmation.

Step 9: Test Functionality

  1. Test product search functionality.
  2. Test transactional emails by placing test orders.
  3. Capture payments using the Stripe plugin.
  4. Ensure CORS settings are configured for security.

Step 10: Implement Object Storage

  1. Install the Spaces object storage plugin for storing media files.
  2. Generate API keys and configure the Spaces plugin.
  3. Update remote environmental variables and deploy the changes.

Step 11: Finalize Deployment

  1. Configure the storefront to fetch images from the Spaces bucket.
  2. Commit the changes to GitHub and trigger a new deployment on Vercel.
  3. Verify that the product images are loaded from the Digital Ocean Spaces bucket.

Congratulations! You have successfully built and deployed a production-ready MedusaJS shop using Digital Ocean and Vercel. If you have any questions, feel free to reach out for assistance.