Files
medusa-store/www/apps/docs/content/deployments/server/general-guide.md
Shahed Nasser fa7c94b4cc docs: create docs workspace (#5174)
* docs: migrate ui docs to docs universe

* created yarn workspace

* added eslint and tsconfig configurations

* fix eslint configurations

* fixed eslint configurations

* shared tailwind configurations

* added shared ui package

* added more shared components

* migrating more components

* made details components shared

* move InlineCode component

* moved InputText

* moved Loading component

* Moved Modal component

* moved Select components

* Moved Tooltip component

* moved Search components

* moved ColorMode provider

* Moved Notification components and providers

* used icons package

* use UI colors in api-reference

* moved Navbar component

* used Navbar and Search in UI docs

* added Feedback to UI docs

* general enhancements

* fix color mode

* added copy colors file from ui-preset

* added features and enhancements to UI docs

* move Sidebar component and provider

* general fixes and preparations for deployment

* update docusaurus version

* adjusted versions

* fix output directory

* remove rootDirectory property

* fix yarn.lock

* moved code component

* added vale for all docs MD and MDX

* fix tests

* fix vale error

* fix deployment errors

* change ignore commands

* add output directory

* fix docs test

* general fixes

* content fixes

* fix announcement script

* added changeset

* fix vale checks

* added nofilter option

* fix vale error
2023-09-21 20:57:15 +03:00

4.3 KiB
Raw Blame History

description, addHowToData
description addHowToData
General steps for all hosting providers. true

General Deployment Guide for Medusa Backend

In this guide, youll learn the general steps you need to take when deploying your Medusa backend. This is useful when the platform-specific deployment guides do not include your selected hosting provider.

Prerequisites

Its assumed you already have a Medusa backend installed and configured on your local machine. If not, check out the create-medusa-app guide to install a Medusa project.


(Optional) Step 1: Create GitHub Repository

Many hosting providers allow you to deploy your project directly from GitHub. This makes it easier for you to push changes and updates without having to manually trigger the update in the hosting provider.

If your hosting provider supports that, create a GitHub repository and push your backends code to it.


Step 2: Start Script in package.json

Make sure the start script in your package.json runs migrations, the build command, and the medusa start command:

"start": "npm run build && medusa migrations run && medusa start"

Step 3: Set ssl Database Option

In production, its recommended to set the database_extra option in medusa-config.js to disable the ssl.rejectUnauthorized option:

module.exports = {
  projectConfig: {
    // ...
    database_extra: { ssl: { rejectUnauthorized: false } },
  },
}

Step 4: Setup PostgreSQL Database

Your Medusa backend must connect to a remote PostgreSQL database. If your hosting provider doesnt support creating a PostgreSQL database, you can use Neon.

Once you set up your PostgreSQL database, make sure to have the connection URL to the database at hand so that you can set it later in your environment variables.


(Optional) Step 5: Setup Architectural Services

Aside from PostgreSQL, you may be using modules or plugins that require some additional architectural setup. For example, if youre using the Redis Events Module, you must set up a Redis database and obtain a connection URL to it.


Step 6: Deploy your Backend

You can deploy your backend now to your hosting provider. During or after the deployment process, based on your hosting provider, you need to add the following environment variables:

DATABASE_TYPE=postgres
DATABASE_URL=<YOUR_DB_URL>
JWT_SECRET=<RANDOM_SECRET>
COOKIE_SECRET=<RANDOM_SECRET>
NODE_ENV=production
NPM_CONFIG_PRODUCTION=false

Where:

  • <YOUR_DB_URL> is the connection URL to the PostgreSQL database you set up in step 4.
  • <RANDOM_SECRET> is a random string that will be used to create authentication and cookie tokens. Make sure to set different ones for JWT_SECRET and COOKIE_SECRET.

Make sure to also add any other environment variables relevant to your backend. For example, if youve setup Redis as explained in step 5, make sure to add an environment variable for the Redis connection URL.


Step 7: Test it Out

After youve deployed your backend, you can test it out in different ways:

  • Go to <BACKEND_URL>/health, where <BACKEND_URL> is the URL to your deployed backend. If the deployment was successful, you should see OK printed in your browser.
  • If you deployed the admin dashboard, you can go to <BACKEND_URL>/app to view the admin dashboard. If you changed the value of the admin plugins path configuration, make sure to replace app with that instead.

Set Up CORS Configuration

To connect your storefront and, if deployed separately, your admin dashboard to your deployed Medusa backend, make sure to set up the admin_cors and store_cors configuration in medusa-config.js accordingly.


Create Admin User

If your hosting provider gives you access to execute commands in your deployed Medusa backend project, you can create a new admin user by running the following command in the root directory of your deployed Medusa backend:

npx medusa user --email admin@medusa-test.com --password supersecret