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
- Install Node.js, Git, and PostgreSQL on your machine.
- Clone the Medusa server and storefront repositories to your local machine.
- Install dependencies by running the necessary commands.
- Configure the backend and necessary plugins.
Step 2: Initialize and Commit Code to GitHub
- Initialize Git and commit the code to your GitHub repository for both the backend and frontend folders.
- Push the code to your GitHub repository.
Step 3: Prepare Backend for Deployment
- Create a PostgreSQL database and a cluster on Digital Ocean.
- Modify startup commands in the package.json file and database connection strings in the Medusa config file.
- Make changes to the .gitignore file to ensure sensitive files are not committed.
- Commit the changes to your GitHub repository.
Step 4: Create App Hosting on Digital Ocean
- Connect your GitHub repository to Digital Ocean.
- Configure app settings such as RAM, auto-scaling, and port.
- Add project configuration modules and environmental variables.
- Deploy the app on Digital Ocean.
Step 5: Attach Resources to the App
- Attach the PostgreSQL database and Redis to the app.
- Configure environmental variables by referencing the database names and URLs.
Step 6: Create Admin User and Configure Storefront
- Create an admin user by connecting to the database from your local machine.
- Set up regions for your store.
- Prepare the storefront for deployment on Vercel.
- Deploy the storefront on Vercel.
Step 7: Add Plugins to the Store
- Enable product search using Meilisearch.
- Configure Meilisearch in the Medusa config file and add it to the list of plugins.
- Add necessary configurations to the Next.js storefront template.
Step 8: Configure Payment and Transactional Emails
- Install and configure the Stripe plugin in Medusa for payments.
- Set up Stripe endpoints and add necessary environmental variables.
- Install and configure the SendGrid plugin for transactional emails.
- Create dynamic email templates for order confirmation.
Step 9: Test Functionality
- Test product search functionality.
- Test transactional emails by placing test orders.
- Capture payments using the Stripe plugin.
- Ensure CORS settings are configured for security.
Step 10: Implement Object Storage
- Install the Spaces object storage plugin for storing media files.
- Generate API keys and configure the Spaces plugin.
- Update remote environmental variables and deploy the changes.
Step 11: Finalize Deployment
- Configure the storefront to fetch images from the Spaces bucket.
- Commit the changes to GitHub and trigger a new deployment on Vercel.
- 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.