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
This commit is contained in:
Shahed Nasser
2023-09-21 20:57:15 +03:00
committed by GitHub
parent 19c5d5ba36
commit fa7c94b4cc
3209 changed files with 32188 additions and 31018 deletions
@@ -0,0 +1,187 @@
---
description: 'Learn how to integrate Spaces with the Medusa backend. Learn how to install and configure the Spaces plugin on the Medusa backend.'
addHowToData: true
---
# Spaces
In this document, youll learn how to install the [Spaces plugin](https://github.com/medusajs/medusa/tree/master/packages/medusa-file-spaces) on your Medusa backend and use it for storage.
<div>
<video width="100%" height="100%" playsinline autoplay muted controls>
<source src="https://user-images.githubusercontent.com/59018053/154808767-7c030254-1879-41fd-a71c-b31c5508d8a4.mp4" type="video/mp4" />
</video>
</div>
## Overview
To manage images in Medusa, you need a file service plugin responsible for hosting the images. Without a file service plugin, you will face issues while working with Medusa, such as when uploading images for products.
Medusa provides three different options to handle your file storage. This document focuses on using [Spaces](https://www.digitalocean.com/products/spaces) to store images and files uploaded to the Medusa backend.
---
## Prerequisites
### Medusa Backend
A Medusa backend is required to be set up before following along with this document. You can follow the [quickstart guide](../../development/backend/install.mdx) to get started in minutes.
### Required Accounts
You need to [create a DigitalOcean account](https://cloud.digitalocean.com/registrations/new) to follow along with this documentation. A credit card is required during registration.
---
## Create DigitalOcean Space
In your DigitalOcean account, click on the Create button at the top right, then choose Spaces from the dropdown.
![Click on the green Create button at the top right, then choose Spaces in the dropdown](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000907/Medusa%20Docs/Spaces/AQqMRoJ_uhkywh.png)
In the Create a Space form, you can choose any of the regions listed. You can alternatively leave all settings as they are and scroll down to the Finalize and Create section.
![The Space form can be left as is and move towards the Finalize and Create section](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000929/Medusa%20Docs/Spaces/ipsIqoA_zeyfkf.png)
In the Finalize and Create section, enter a name for the field “Choose a unique name”. Youll use this name later in the integration with Medusa. Also, select the project you want to add the new Space to.
![Enter a name for the Space in the Choose a unique name field](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000949/Medusa%20Docs/Spaces/NhlRX0h_ptdhpk.png)
Once youre done, click on the Create a Space button. This creates the Space and redirects you to the Spaces page.
---
## Create Space Access Keys
Choose API from the bottom of the sidebar.
![Choose API from the bottom of the sidebar.](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000964/Medusa%20Docs/Spaces/6zNoDOW_tqbeqv.png)
This opens the Application & API page. Scroll down to Spaces Access Keys and click the Generate New Key button.
![In the Spaces access keys section, click the Generate New Key button](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000977/Medusa%20Docs/Spaces/NUocdgh_doi0dq.png)
This shows a table with the Name field editable. Enter a name for the Access Keys and click on the checkmark button to save and generate the Spaces access keys.
![Enter a name for the Space access key in the field under the Name column](https://res.cloudinary.com/dza7lstvk/image/upload/v1668000987/Medusa%20Docs/Spaces/ihJBx0T_xfe4rh.png)
Then, two keys will be available under the Key column of the table. The first one is the Access Key ID and the second is the Secret Access Key. Copy both as youll use them later.
:::caution
The secret access key will not be shown again after you leave the page. Make sure to copy it when you see it or youll need to re-generate a new one.
:::
---
## Install the Spaces Plugin
In the directory of your Medusa backend, run the following command to install the Spaces plugin:
```bash npm2yarn
npm install medusa-file-spaces
```
Then, add the following environment variables:
```bash
SPACE_URL=<YOUR_SPACE_URL>
SPACE_BUCKET=<YOUR_SPACE_NAME>
SPACE_ENDPOINT=<YOUR_SPACE_ENDPOINT>
SPACE_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID>
SPACE_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY>
```
Where:
1. `<YOUR_SPACE_URL>` is the URL of your Space which you can find on the Spaces page below the Spaces name.
![The URL is available under the Space's name on the Space's page](https://res.cloudinary.com/dza7lstvk/image/upload/v1668001004/Medusa%20Docs/Spaces/cA3vkvh_maixr0.png)
2. `<YOUR_SPACE_NAME>` is the name of your Space.
3. `<YOUR_SPACE_ENDPOINT>` is your Spaces endpoint which can be found by going to your Spaces page, clicking on the Settings tab, and scrolling to the Endpoint section.
![Endpoint can be found on the Settings tab in the Space's page](https://res.cloudinary.com/dza7lstvk/image/upload/v1668001017/Medusa%20Docs/Spaces/CnvLr6R_tudlhu.png)
4. `<YOUR_ACCESS_KEY_ID>` and `<YOUR_SECRET_ACCESS_KEY>` are the keys you created in the previous section.
Finally, in `medusa-config.js` add a new item to the `plugins` array:
```jsx title=medusa-config.js
const plugins = [
// ...
{
resolve: `medusa-file-spaces`,
options: {
spaces_url: process.env.SPACE_URL,
bucket: process.env.SPACE_BUCKET,
endpoint: process.env.SPACE_ENDPOINT,
access_key_id: process.env.SPACE_ACCESS_KEY_ID,
secret_access_key: process.env.SPACE_SECRET_ACCESS_KEY,
},
},
]
```
:::caution
If you have multiple storage plugins configured, the last plugin declared in the `medusa-config.js` file will be used.
:::
---
## Test the Space Plugin
Run your Medusa backend with the following command:
```bash npm2yarn
npx medusa develop
```
Then, you can either test the plugin using the [REST APIs](https://docs.medusajs.com/api/store) or using the [Medusa Admin](../../admin/quickstart.mdx).
On the Medusa Admin, create a new product and, in the Images section, upload an image then click Save. If the integration was successful, the product image will be uploaded successfully.
![Image successfully uploaded on Medusa's admin](https://res.cloudinary.com/dza7lstvk/image/upload/v1668001039/Medusa%20Docs/Spaces/oTi4jIw_c6vefa.png)
You can also check that the image was uploaded on the Spaces page.
![Image can be seen on the Space's page on DigitalOcean](https://res.cloudinary.com/dza7lstvk/image/upload/v1668001050/Medusa%20Docs/Spaces/BexmRkg_gimk1d.png)
---
## Next.js Starter Template Configuration
If youre using a [Next.js Starter Template](../../starters/nextjs-medusa-starter.mdx), you need to add an additional configuration that adds the Spaces domain name into the configured images domain names. This is because all URLs of product images will be from the Space.
If this configuration is not added, youll receive the error ["next/image Un-configured Host”](https://nextjs.org/docs/messages/next-image-unconfigured-host).
In `next.config.js` add the following option in the exported object:
```jsx title=next.config.js
const { withStoreConfig } = require("./store-config")
// ...
module.exports = withStoreConfig({
// ...
images: {
domains: [
// ...
"<YOUR_SPACE_DOMAIN>",
],
},
})
```
Where `<YOUR_SPACE_DOMAIN>` is the domain name for your Space which can be retrieved from the Space URL. For example, `medusa-backend.digitaloceanspaces.com`.
---
## See Also
- Check out [more plugins](../overview.mdx) you can add to your store
- [Deploy the Medusa backend on DigitalOcean](../../deployments/server/deploying-on-digital-ocean.md)
- Install the [Next.js Starter Template](../../starters/nextjs-medusa-starter.mdx)