docs: small fixes across documentation (#3815)

This commit is contained in:
Shahed Nasser
2023-04-12 15:04:09 +03:00
committed by GitHub
parent 8e7e346683
commit bd21277142
4 changed files with 79 additions and 71 deletions
@@ -13,9 +13,9 @@ This documentation does not explain the basics of [middlewares](./add-middleware
## Step 1: Create the Middleware ## Step 1: Create the Middleware
Create the file `src/api/middlewareds/logged-in-user.ts` with the following content: Create the file `src/api/middlewares/logged-in-user.ts` with the following content:
```ts title=src/api/middlewareds/logged-in-user.ts ```ts title=src/api/middlewares/logged-in-user.ts
import { User, UserService } from "@medusajs/medusa" import { User, UserService } from "@medusajs/medusa"
export async function registerLoggedInUser(req, res, next) { export async function registerLoggedInUser(req, res, next) {
@@ -43,7 +43,13 @@ This retrieves the ID of the current user to retrieve an instance of it, then re
## Step 2: Apply Middleware on Endpoint ## Step 2: Apply Middleware on Endpoint
Create the file `src/api/routes/create-product.ts` with the following content: If you don't have the `cors` package installed, make sure to install it first:
```bash npm2yarn
npm install cors
```
Then, create the file `src/api/routes/create-product.ts` with the following content:
```ts title=src/api/routes/create-product.ts ```ts title=src/api/routes/create-product.ts
import cors from "cors" import cors from "cors"
@@ -91,7 +97,7 @@ Create the file `src/api/index.ts` with the following content:
import configLoader from "@medusajs/medusa/dist/loaders/config" import configLoader from "@medusajs/medusa/dist/loaders/config"
import createProductRouter from "./routes/create-product" import createProductRouter from "./routes/create-product"
export default async function (rootDirectory: string) { export default function (rootDirectory: string) {
const config = await configLoader(rootDirectory) const config = await configLoader(rootDirectory)
const adminCors = { const adminCors = {
@@ -12,7 +12,7 @@ In this document, youll learn how to create a [Migration](./overview.mdx) usi
To create a migration that makes changes to your Medusa schema, run the following command: To create a migration that makes changes to your Medusa schema, run the following command:
```bash ```bash
npx typeorm migration:create -n UserChanged --dir src/migrations npx typeorm migration:create src/migrations/UserChanged
``` ```
This will create the migration file in the path you specify. You can use this without the need to install Typeorm's CLI tool. You can then go ahead and make changes to it as necessary. This will create the migration file in the path you specify. You can use this without the need to install Typeorm's CLI tool. You can then go ahead and make changes to it as necessary.
@@ -57,7 +57,7 @@ import {
class ProductService extends MedusaProductService { class ProductService extends MedusaProductService {
// The default life time for a core service is SINGLETON // The default life time for a core service is SINGLETON
static LIFE_TIME = LifeTime.SCOPED static LIFE_TIME = Lifetime.SCOPED
// ... // ...
} }
+67 -65
View File
@@ -1,14 +1,14 @@
require('dotenv').config(); require("dotenv").config()
const path = require("path") const path = require("path")
const fs = require("fs") const fs = require("fs")
const docsPath = path.join(__dirname, "../../docs/content") const docsPath = path.join(__dirname, "../../docs/content")
const apisPath = path.join(__dirname, "../../docs/api") const apisPath = path.join(__dirname, "../../docs/api")
const reverseSidebar = require('./src/utils/reverseSidebar') const reverseSidebar = require("./src/utils/reverseSidebar")
const algoliaAppId = process.env.ALGOLIA_APP_ID || "temp" const algoliaAppId = process.env.ALGOLIA_APP_ID || "temp"
const algoliaApiKey = process.env.ALGOLIA_API_KEY || "temp" const algoliaApiKey = process.env.ALGOLIA_API_KEY || "temp"
const announcementBar = JSON.parse(fs.readFileSync('./announcement.json')) const announcementBar = JSON.parse(fs.readFileSync("./announcement.json"))
/** @type {import('@docusaurus/types').DocusaurusConfig} */ /** @type {import('@docusaurus/types').DocusaurusConfig} */
const config = { const config = {
@@ -25,15 +25,15 @@ const config = {
[ [
"docusaurus-plugin-segment", "docusaurus-plugin-segment",
{ {
apiKey: process.env.SEGMENT_API_KEY || "temp" apiKey: process.env.SEGMENT_API_KEY || "temp",
} },
], ],
require.resolve("docusaurus-plugin-image-zoom"), require.resolve("docusaurus-plugin-image-zoom"),
], ],
themeConfig: { themeConfig: {
image: 'img/docs-banner.jpg', image: "img/docs-banner.jpg",
colorMode: { colorMode: {
defaultMode: 'light', defaultMode: "light",
disableSwitch: false, disableSwitch: false,
respectPrefersColorScheme: true, respectPrefersColorScheme: true,
}, },
@@ -43,7 +43,7 @@ const config = {
placeholder: "Search docs...", placeholder: "Search docs...",
appId: algoliaAppId, appId: algoliaAppId,
contextualSearch: false, contextualSearch: false,
externalUrlRegex: "https://medusajs.com" externalUrlRegex: "https://medusajs.com",
}, },
prism: { prism: {
defaultLanguage: "js", defaultLanguage: "js",
@@ -51,46 +51,46 @@ const config = {
theme: require("./src/themes/medusaDocs"), theme: require("./src/themes/medusaDocs"),
}, },
zoom: { zoom: {
selector: '.markdown :not(.no-zoom-img) > img:not(.no-zoom-img)' selector: ".markdown :not(.no-zoom-img) > img:not(.no-zoom-img)",
}, },
navbar: { navbar: {
hideOnScroll: false, hideOnScroll: false,
logo: { logo: {
alt: "Medusa", alt: "Medusa",
src: "img/logo.png", src: "img/logo.png",
srcDark: "img/logo-dark.png" srcDark: "img/logo-dark.png",
}, },
items: [ items: [
{ {
type: 'search', type: "search",
position: 'left', position: "left",
}, },
{ {
type: "docSidebar", type: "docSidebar",
sidebarId: "homepage", sidebarId: "homepage",
label: "Docs", label: "Docs",
position: "right" position: "right",
}, },
{ {
type: "docSidebar", type: "docSidebar",
sidebarId: "userGuideSidebar", sidebarId: "userGuideSidebar",
label: "User Guide", label: "User Guide",
position: "right" position: "right",
}, },
{ {
href: "/api/store", href: "/api/store",
label: "Store API", label: "Store API",
prependBaseUrlToHref: true, prependBaseUrlToHref: true,
target: '_blank', target: "_blank",
position: "right" position: "right",
}, },
{ {
href: "/api/admin", href: "/api/admin",
label: "Admin API", label: "Admin API",
prependBaseUrlToHref: true, prependBaseUrlToHref: true,
target: '_blank', target: "_blank",
position: "right" position: "right",
} },
], ],
}, },
navbarActions: [ navbarActions: [
@@ -98,51 +98,49 @@ const config = {
type: "link", type: "link",
href: "https://github.com/medusajs/medusa/issues/new?assignees=&labels=type%3A+docs&template=docs.yml", href: "https://github.com/medusajs/medusa/issues/new?assignees=&labels=type%3A+docs&template=docs.yml",
title: "Report an Issue", title: "Report an Issue",
icon: "report" icon: "report",
} },
], ],
footer: { footer: {
copyright: `© ${new Date().getFullYear()} Medusa, Inc. All rights reserved.`, copyright: `© ${new Date().getFullYear()} Medusa, Inc. All rights reserved.`,
}, },
socialLinks: [ socialLinks: [
{ {
type: 'discord', type: "discord",
href: 'https://discord.gg/medusajs' href: "https://discord.gg/medusajs",
}, },
{ {
type: 'twitter', type: "twitter",
href: 'https://twitter.com/medusajs' href: "https://twitter.com/medusajs",
}, },
{ {
type: 'linkedin', type: "linkedin",
href: 'https://www.linkedin.com/company/medusajs' href: "https://www.linkedin.com/company/medusajs",
}, },
{ {
type: 'github', type: "github",
href: 'https://github.com/medusajs/medusa' href: "https://github.com/medusajs/medusa",
} },
], ],
reportCodeLinkPrefix: 'https://github.com/medusajs/medusa/issues/new?assignees=&labels=type%3A+docs&template=docs.yml', reportCodeLinkPrefix:
"https://github.com/medusajs/medusa/issues/new?assignees=&labels=type%3A+docs&template=docs.yml",
footerFeedback: { footerFeedback: {
event: 'survey' event: "survey",
}, },
docs: { docs: {
sidebar: { sidebar: {
autoCollapseCategories: true autoCollapseCategories: true,
} },
}, },
cloudinaryConfig: { cloudinaryConfig: {
cloudName: process.env.CLOUDINARY_CLOUD_NAME || "", cloudName: process.env.CLOUDINARY_CLOUD_NAME || "",
flags: [ flags: ["fl_lossy", "f_auto"],
'fl_lossy',
'f_auto'
],
resize: { resize: {
action: 'pad', action: "pad",
aspectRatio: '16:9' aspectRatio: "16:9",
}, },
roundCorners: 16 roundCorners: 16,
} },
}, },
presets: [ presets: [
[ [
@@ -150,50 +148,54 @@ const config = {
{ {
docs: { docs: {
sidebarPath: require.resolve("./sidebars.js"), sidebarPath: require.resolve("./sidebars.js"),
editUrl: "https://github.com/medusajs/medusa/edit/master/docs/content", editUrl:
"https://github.com/medusajs/medusa/edit/develop/docs/content",
path: docsPath, path: docsPath,
routeBasePath: "/", routeBasePath: "/",
remarkPlugins: [ remarkPlugins: [
[require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}], [require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],
], ],
showLastUpdateTime: true, showLastUpdateTime: true,
// breadcrumbs: false, // breadcrumbs: false,
async sidebarItemsGenerator({defaultSidebarItemsGenerator, ...args}) { async sidebarItemsGenerator({
const sidebarItems = await defaultSidebarItemsGenerator(args); defaultSidebarItemsGenerator,
return reverseSidebar(sidebarItems, args.item); ...args
}) {
const sidebarItems = await defaultSidebarItemsGenerator(args)
return reverseSidebar(sidebarItems, args.item)
}, },
}, },
theme: { theme: {
customCss: require.resolve("./src/css/custom.css") customCss: require.resolve("./src/css/custom.css"),
}, },
gtag: { gtag: {
trackingID: 'G-S7G7X3JYS3', trackingID: "G-S7G7X3JYS3",
}, },
}, },
], ],
[ [
'redocusaurus', "redocusaurus",
{ {
// Plugin Options for loading OpenAPI files // Plugin Options for loading OpenAPI files
specs: [ specs: [
{ {
spec: path.join(apisPath, 'store/openapi.yaml'), spec: path.join(apisPath, "store/openapi.yaml"),
route: '/api/store', route: "/api/store",
layout: { layout: {
noFooter: true noFooter: true,
} },
}, },
{ {
spec: path.join(apisPath, 'admin/openapi.yaml'), spec: path.join(apisPath, "admin/openapi.yaml"),
route: '/api/admin', route: "/api/admin",
layout: { layout: {
noFooter: true noFooter: true,
} },
} },
], ],
// Theme Options for modifying how redoc renders them // Theme Options for modifying how redoc renders them
theme: { theme: {
primaryColorDark: '#161618', primaryColorDark: "#161618",
options: { options: {
disableSearch: true, disableSearch: true,
nativeScrollbars: true, nativeScrollbars: true,
@@ -203,14 +205,14 @@ const config = {
generatedPayloadSamplesMaxDepth: 4, generatedPayloadSamplesMaxDepth: 4,
showObjectSchemaExamples: true, showObjectSchemaExamples: true,
requiredPropsFirst: true, requiredPropsFirst: true,
hideRequestPayloadSample: true hideRequestPayloadSample: true,
}, },
theme: { theme: {
sidebar: { sidebar: {
width: '250px' width: "250px",
} },
} },
} },
}, },
], ],
], ],