### Installation Source: https://docs.strapi.io/llms Learn about the many different options to install Strapi and get started using it. ```APIDOC ## Installation ### Description Provides information on various methods for installing Strapi and getting started. ### Method GET ### Endpoint /cms/installation ### Parameters None ### Request Example None ### Response #### Success Response (200) - **installationOptions** (array) - An array detailing different installation methods (e.g., npm, Docker, Cloud). - **gettingStartedGuide** (string) - A guide to help users begin using Strapi after installation. #### Response Example ```json { "installationOptions": [ { "method": "npm", "description": "Install Strapi globally or locally using npm or yarn.", "command": "npx create-strapi-app my-project --quickstart" }, { "method": "Docker", "description": "Deploy Strapi using Docker containers.", "guide": "Refer to the Docker documentation for setup." } ], "gettingStartedGuide": "After installation, you can access the Strapi admin panel at /admin to start creating your content types and managing your data." } ``` ``` -------------------------------- ### Configure Windows Start Script Source: https://docs.strapi.io/cms/deployment Instructions to install 'cross-env' (if not already installed) and configure a Windows-specific start script in package.json. This enables running the server with production settings on Windows. ```shell npm install cross-env ``` ```json "start:win": "cross-env NODE_ENV=production npm start" ``` ```shell npm run start:win ``` -------------------------------- ### Installing Strapi via NPM Source: https://docs.strapi.io/llms This command uses npm to create a new Strapi project. It's the most common way to get started with Strapi, setting up a new project with the default configuration. ```bash npx create-strapi-app my-project --quickstart ``` -------------------------------- ### Setting up Strapi Instance for Testing Source: https://docs.strapi.io/cms/testing The 'setupStrapi' function initializes and starts a Strapi instance for testing. It handles environment variable setup, database configuration, and potentially TypeScript support for configuration files. It also registers a '/hello' route and patches the user service for default role assignment. After setup, it starts the Strapi server and assigns the instance to 'global.strapi'. ```javascript async function setupStrapi(overrides) { // ... (implementation details for setup) // Example: Ensure database is clean before starting await cleanupStrapi(); // ... (rest of the setup logic) await instance.start(); global.strapi = instance; // ... (seeding and patching logic) return instance; } ``` -------------------------------- ### Install Jest and Supertest (NPM) Source: https://docs.strapi.io/cms/testing Installs Jest for test running and Supertest for HTTP testing as development dependencies using NPM. ```bash npm install jest supertest --save-dev ``` -------------------------------- ### Strapi Server Startup Commands Source: https://docs.strapi.io/cms/configurations/environment Provides examples of starting a Strapi server with different host configurations based on environment variables and yarn commands. Demonstrates how NODE_ENV and HOST variables affect the server's startup. ```bash yarn start # uses host 127.0.0.1 NODE_ENV=production yarn start # uses host defined in .env. If not defined, uses 0.0.0.0 HOST=10.0.0.1 NODE_ENV=production yarn start # uses host 10.0.0.1 ``` -------------------------------- ### Install Jest and Supertest (Yarn) Source: https://docs.strapi.io/cms/testing Installs Jest for test running and Supertest for HTTP testing as development dependencies using Yarn. ```bash yarn add jest supertest --dev ``` -------------------------------- ### Create Strapi Project using pnpm Source: https://docs.strapi.io/cms/installation/cli Command to create a new Strapi project using pnpm. The `pnpm create strapi` command starts the Strapi project setup. Be aware that pnpm projects might have compatibility issues with Strapi Cloud. ```bash pnpm create strapi ``` -------------------------------- ### Create New Strapi Project Source: https://docs.strapi.io/cms/quick-start Command to initiate a new Strapi project. This command downloads and runs the latest Strapi creation script, creating a new project directory with the specified name. Ensure Node.js and a package manager (npm, yarn, or pnpm) are installed. ```bash npx create-strapi@latest my-strapi-project ``` -------------------------------- ### Strapi Plugin Creation and Linking Source: https://docs.strapi.io/llms Guides for creating and linking Strapi plugins, including setup without a Strapi project and connecting to an existing app using `watch:link` and `yalc`. Covers bundling for distribution. ```shell npm run strapi develop -- --watch-admin yarn develop -- --watch-admin ``` ```shell npm run strapi plugin:build yarn plugin:build ``` ```shell npm run strapi plugin:package yarn plugin:package ``` ```shell npm run strapi plugin:install yarn plugin:install ``` ```shell npm run strapi plugin:uninstall yarn plugin:uninstall ``` -------------------------------- ### Run Strapi Development Server Source: https://docs.strapi.io/cms/quick-start Commands to start the Strapi development server and navigate to the project directory. The 'npm run develop' command starts the server, typically accessible at http://localhost:1337/admin. Use 'yarn develop' if Yarn is your package manager. This command is essential for accessing the Strapi admin panel and building content structures. ```bash cd my-strapi-project && npm run develop ``` ```bash cd my-strapi-project && yarn develop ``` -------------------------------- ### Test Basic API Endpoint: Hello World (JavaScript) Source: https://docs.strapi.io/cms/testing An example of `tests/hello.test.js` to test a basic API endpoint in Strapi. It utilizes `supertest` to send a GET request to `/api/hello` and asserts that the response status is 200 and the text content is 'Hello World!'. It also relies on `setupStrapi` and `cleanupStrapi`. ```javascript const { setupStrapi, cleanupStrapi } = require('./strapi'); const request = require('supertest'); beforeAll(async () => { await setupStrapi(); }); afterAll(async () => { await cleanupStrapi(); }); it('should return hello world', async () => { await request(strapi.server.httpServer) .get('/api/hello') .expect(200) .then((data) => { expect(data.text).toBe('Hello World!'); }); }); ``` -------------------------------- ### Create Strapi Plugin with Plugin SDK Source: https://docs.strapi.io/llms-full Initiates a new Strapi plugin using the Plugin SDK CLI. This command guides users through setup prompts to generate a basic plugin structure, suitable for local development or publishing. ```bash npx @strapi/plugin-new my-strapi-plugin ``` -------------------------------- ### Strapi: Basic Controller Action (TypeScript) Source: https://docs.strapi.io/cms/backend-customization/controllers This TypeScript controller demonstrates a simple 'index' action that responds with 'Hello World!' to a GET request at '/hello'. It's a basic example of Strapi's default controller structure. ```typescript export default { async index(ctx, next) { ctx.body = 'Hello World!'; }, }; ``` -------------------------------- ### Example Strapi .env File Configuration (Environment Variables) Source: https://docs.strapi.io/cms/deployment This example shows a typical .env file for a Strapi project, used to set environment-specific variables. These variables, such as HOST and PORT, can override default configuration values and are essential for tailoring the application's behavior in different deployment environments. The file format is a simple key-value pair. ```dotenv HOST=10.0.0.1 PORT=1338 ``` -------------------------------- ### Strapi Server Startup with Environment Variables Source: https://docs.strapi.io/assets/files/llms-full-e8ba8b5875941be5a32e24360def8055 Demonstrates how to start the Strapi server using `yarn start` with different environment variables to control the host address. This is useful for defining the network interface Strapi listens on during development and production. ```bash yarn start NODE_ENV=production yarn start HOST=10.0.0.1 NODE_ENV=production yarn start ``` -------------------------------- ### GET /api/restaurants Source: https://docs.strapi.io/cms/quick-start Retrieves a list of all restaurants available in the Strapi project. This endpoint allows you to fetch restaurant data, including their details, creation, and update timestamps. ```APIDOC ## GET /api/restaurants ### Description Retrieves a list of all restaurants available in the Strapi project. This endpoint allows you to fetch restaurant data, including their details, creation, and update timestamps. ### Method GET ### Endpoint /api/restaurants ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of items per page. ### Request Example ### Response #### Success Response (200) - **data** (array) - An array of restaurant objects. Each object contains: - **id** (integer) - The unique identifier of the restaurant. - **documentId** (string) - The document ID for the restaurant. - **Name** (string) - The name of the restaurant. - **Description** (array) - An array containing the description of the restaurant, typically with rich text formatting. - **createdAt** (string) - The timestamp when the restaurant was created. - **updatedAt** (string) - The timestamp when the restaurant was last updated. - **publishedAt** (string) - The timestamp when the restaurant was published. - **locale** (string or null) - The locale of the restaurant content. - **meta** (object) - Metadata for the response, including pagination details. - **pagination** (object) - Pagination information. - **page** (integer) - The current page number. - **pageSize** (integer) - The number of items per page. - **pageCount** (integer) - The total number of pages. - **total** (integer) - The total number of restaurants. #### Response Example ```json { "data": [ { "id": 3, "documentId": "wf7m1n3g8g22yr5k50hsryhk", "Name": "Biscotte Restaurant", "Description": [ { "type": "paragraph", "children": [ { "type": "text", "text": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers." } ] } ], "createdAt": "2024-09-10T12:49:32.350Z", "updatedAt": "2024-09-10T13:14:18.275Z", "publishedAt": "2024-09-10T13:14:18.280Z", "locale": null } ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 1, "total": 1 } } } ``` ``` -------------------------------- ### Create Strapi Project with Quickstart Source: https://docs.strapi.io/cms/data-management/transfer Initializes a new Strapi project with the quickstart option, which sets up a default database and admin panel. This command is the first step in creating a Strapi application. ```bash npx create-strapi-app@latest --quickstart ``` -------------------------------- ### Strapi Application Creation with SQLite Quickstart (NPM) Source: https://docs.strapi.io/cms/configurations/database Command to create a new Strapi application using npm with the SQLite database pre-configured for a quick start. This command initializes a new project and launches it, enabling rapid local development with SQLite. ```bash npx create-strapi-app@latest my-project --quickstart ``` -------------------------------- ### Example Strapi API Response (JSON) Source: https://docs.strapi.io/cms/quick-start This JSON object represents the data structure returned when querying the /api/restaurants endpoint of a Strapi project. It includes details about restaurants, pagination metadata, and timestamps. ```json { "data": [ { "id": 3, "documentId": "wf7m1n3g8g22yr5k50hsryhk", "Name": "Biscotte Restaurant", "Description": [ { "type": "paragraph", "children": [ { "type": "text", "text": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers." } ] } ], "createdAt": "2024-09-10T12:49:32.350Z", "updatedAt": "2024-09-10T13:14:18.275Z", "publishedAt": "2024-09-10T13:14:18.280Z", "locale": null } ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 1, "total": 1 } } } ``` -------------------------------- ### Minimal Strapi Admin Configuration (JavaScript) Source: https://docs.strapi.io/cms/configurations/admin-panel This JavaScript configuration sets up essential parameters for Strapi's admin panel, including authentication secrets and API token salts. It utilizes environment variables for security and flexibility. This is a basic setup for getting started. ```javascript module.exports = ({ env }) => ({ apiToken: { salt: env('API_TOKEN_SALT', 'someRandomLongString'), }, auditLogs: { // only accessible with an Enterprise plan enabled: env.bool('AUDIT_LOGS_ENABLED', true), }, auth: { secret: env('ADMIN_JWT_SECRET', 'someSecretKey'), }, transfer: { token: { salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'), } }, }); ``` -------------------------------- ### Strapi Application Creation with SQLite Quickstart (Yarn) Source: https://docs.strapi.io/cms/configurations/database Command to create a new Strapi application using Yarn with the SQLite database pre-configured for a quick start. This command automatically sets up the project structure and launches the application with default SQLite settings. ```bash yarn create strapi-app my-project --quickstart ``` -------------------------------- ### Migrating to Strapi 5 - Introduction and FAQ Source: https://docs.strapi.io/llms Learn more about how to upgrade to Strapi 5 with an introduction and frequently asked questions. ```APIDOC ## Migrating to Strapi 5 - Introduction and FAQ ### Description Provides an introduction to upgrading to Strapi 5 and answers frequently asked questions about the process. ### Method GET ### Endpoint /cms/migration/v4 ``` -------------------------------- ### GET /api/articles with Detailed Population Source: https://docs.strapi.io/cms/api/rest/guides/understanding-populate This example shows a GET request to the /api/articles endpoint with a detailed population strategy for dynamic zones and components. ```APIDOC ## GET /api/articles ### Description Retrieves a list of articles with specific dynamic zone and component population. ### Method GET ### Endpoint `/api/articles` ### Query Parameters - **populate** (string) - Required - Specifies the population strategy for related data. - `[blocks][on][blocks.related-articles][populate][articles][populate][0]=image` - Deeply populates the `articles` relation within the `related-articles` component, including the `image` field. - `[blocks][on][blocks.cta-command-line][populate]=*` - Populates all fields for the `cta-command-line` component. ### Request Example ``` GET /api/articles?populate[blocks][on][blocks.related-articles][populate][articles][populate][0]=image&populate[blocks][on][blocks.cta-command-line][populate]=* ``` ### Response #### Success Response (200) - **data** (array) - An array of article objects. - **id** (integer) - The unique identifier of the article. - **documentId** (string) - The document ID of the article. - **title** (string) - The title of the article. - **slug** (string) - The slug of the article. - **createdAt** (string) - The creation timestamp of the article. - **updatedAt** (string) - The update timestamp of the article. - **publishedAt** (string) - The publication timestamp of the article. - **locale** (string) - The locale of the article. - **ckeditor_content** (string) - The content of the article in CKEditor format. - **blocks** (array) - An array of block components within the article. - **id** (integer) - The unique identifier of the block. - **documentId** (string) - The document ID of the block. - **__component** (string) - The type of the block component (e.g., `blocks.related-articles`, `blocks.cta-command-line`). - **articles** (object) - Contains related articles (if `blocks.related-articles` component). - **data** (array) - Array of related article objects. - **id** (integer) - The unique identifier of the related article. - **documentId** (string) - The document ID of the related article. - **title** (string) - The title of the related article. - **slug** (string) - The slug of the related article. - **createdAt** (string) - The creation timestamp of the related article. - **updatedAt** (string) - The update timestamp of the related article. - **publishedAt** (string) - The publication timestamp of the related article. - **locale** (string) - The locale of the related article. - **ckeditor_content** (string) - The content of the related article. - **image** (object) - The image associated with the related article. - **theme** (string) - The theme of the CTA component (if `blocks.cta-command-line` component). - **title** (string) - The title of the CTA component. - **text** (string) - The text of the CTA component. - **commandLine** (string) - The command line string of the CTA component. - **meta** (object) - Metadata for pagination. - **pagination** (object) - Pagination details. - **page** (integer) - The current page number. - **pageSize** (integer) - The number of items per page. - **pageCount** (integer) - The total number of pages. - **total** (integer) - The total number of items. #### Response Example ```json { "data": [ { "id": 1, "documentId": "it9bbhcgc6mcfsqas7h1dp", "title": "Here's why you have to try basque cuisine, according to a basque chef", "slug": "here-s-why-you-have-to-try-basque-cuisine-according-to-a-basque-chef", "createdAt": "2021-11-09T13:33:19.948Z", "updatedAt": "2023-06-02T10:57:19.584Z", "publishedAt": "2022-09-22T09:30:00.208Z", "locale": "en", "ckeditor_content": "…", "blocks": [ { "id": 2, "documentId": "e8cnux5ejxyqrejd5addfv", "__component": "blocks.related-articles", "articles": { "data": [ { "id": 2, "documentId": "wkgojrcg5bkz8teqx1foz7", "title": "What are chinese hamburgers and why aren't you eating them?", "slug": "what-are-chinese-hamburgers-and-why-aren-t-you-eating-them", "createdAt": "2021-11-11T13:33:19.948Z", "updatedAt": "2023-06-01T14:32:50.984Z", "publishedAt": "2022-09-22T12:36:48.312Z", "locale": "en", "ckeditor_content": "…", "image": { "data": { // … } } } }, { "id": 3, // … }, { "id": 4, // … } ] } }, { "id": 2, "__component": "blocks.cta-command-line", "theme": "primary", "title": "Want to give a try to a Strapi starter?", "text": "❤️", "commandLine": "git clone https://github.com/strapi/nextjs-corporate-starter.git" } ] }, { "id": 2, // … }, { "id": 3, "documentId": "z5jnfvyuj07fogzh1kcbd3", "title": "7 Places worth visiting for the food alone", "slug": "7-places-worth-visiting-for-the-food-alone", "createdAt": "2021-11-12T13:33:19.948Z", "updatedAt": "2023-06-02T11:30:00.075Z", "publishedAt": "2023-06-02T11:30:00.075Z", "locale": "en", "ckeditor_content": "…", "blocks": [ { "id": 1, "documentId": "ks7xsp9fewoi0qljcz9qa0", "__component": "blocks.related-articles", "articles": { // … } }, { "id": 1, "documentId": "c2imt19iywk27hl2ftph7s", "__component": "blocks.cta-command-line", "theme": "secondary", "title": "Want to give it a try with a brand new project?", "text": "Up & running in seconds 🚀", "commandLine": "npx create-strapi-app my-project --quickstart" } ] }, { "id": 4, // … } ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 1, "total": 4 } } } ``` ``` -------------------------------- ### Strapi Webhook Configuration Example Source: https://docs.strapi.io/llms-full Demonstrates how to configure default headers for webhook requests within the Strapi server configuration file. This allows for consistent security measures across multiple webhooks. ```javascript module.exports = ({ env }) => ({ // ... webhooks: { defaultHeaders: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_API_TOKEN' }, }, // ... }); ``` -------------------------------- ### Initialize a New Strapi Plugin (Bash) Source: https://docs.strapi.io/assets/files/llms-full-e8ba8b5875941be5a32e24360def8055 Initializes a new Strapi plugin at a specified path. This command uses `npx` to run the Strapi SDK plugin initializer. It accepts a `path` argument for the plugin's location and supports `--debug` and `--silent` options. ```bash npx @strapi/sdk-plugin init npx @strapi/sdk-plugin init ./src/plugins/my-plugin npx @strapi/sdk-plugin init --debug npx @strapi/sdk-plugin init --silent ``` -------------------------------- ### Start Strapi Server in Production (Yarn/NPM) Source: https://docs.strapi.io/cms/deployment Commands to start the Strapi server in production mode using Yarn or NPM. This ensures the server runs with optimized settings for a live environment. ```shell NODE_ENV=production yarn start ``` ```shell NODE_ENV=production npm run start ``` -------------------------------- ### Strapi CAS Provider Configuration Example Source: https://docs.strapi.io/cms/configurations/users-and-permissions-providers/cas Example configuration values for the CAS provider within Strapi's User & Permissions plugin settings. This includes enabling the provider and setting authentication URLs based on the CAS deployment. ```text Enable : ON Client ID : thestrapiclientid Client Secret : thestrapiclientsecret The redirect URL to your front-end app : http://localhost:1337/api/connect/cas/redirect The Provider Subdomain such that the following URLs are correct for the CAS deployment you are targeting: authorize_url: https://[subdomain]/oidc/authorize access_url: https://[subdomain]/oidc/token profile_url: https://[subdomain]/oidc/profile ``` -------------------------------- ### Initialize a New Strapi Plugin (Bash) Source: https://docs.strapi.io/llms-full Command to create a new Strapi plugin project. It takes an optional 'path' argument to specify the directory for the new plugin. Debug and silent options are available for controlling output. ```bash npx @strapi/sdk-plugin init [path] # Example with default path: npx @strapi/sdk-plugin init # Example with a custom path: npx @strapi/sdk-plugin init ./my-custom-plugin-path ``` -------------------------------- ### Programmatically Start Strapi with `strapi()` Factory Source: https://docs.strapi.io/cms/typescript/development This code example demonstrates how to start a Strapi instance programmatically using the `strapi()` factory in a TypeScript project. It highlights the necessity of providing the `distDir` option to the `createStrapi` method, specifying the directory where the compiled TypeScript code resides. ```javascript const strapi = require('@strapi/strapi'); const app = strapi.createStrapi({ distDir: './dist' }); app.start(); ``` -------------------------------- ### Create Strapi Smoke Tests with Jest Source: https://docs.strapi.io/assets/files/llms-full-e8ba8b5875941be5a32e24360def8055 This snippet demonstrates how to set up a basic Jest test suite to confirm Strapi boots correctly. It includes setup and cleanup functions for the Strapi instance and a simple test to check if the `strapi` object is defined. Ensure the `strapi.js` harness file is correctly referenced. ```javascript const { setupStrapi, cleanupStrapi } = require('./strapi'); /** this code is called once before any test is called */ beforeAll(async () => { await setupStrapi(); // Singleton so it can be called many times }); /** this code is called once before all the tests are finished */ afterAll(async () => { await cleanupStrapi(); }); it('strapi is defined', () => { expect(strapi).toBeDefined(); }); require('./hello'); require('./user'); ``` -------------------------------- ### Documentation Plugin Source: https://docs.strapi.io/llms The Documentation plugin automatically generates OpenAPI/Swagger documentation for your API by scanning content types and routes. This documentation guides through installation, settings customization, and access control. ```APIDOC ## Documentation Plugin ### Description Auto-generates OpenAPI/Swagger docs for your API by scanning content types and routes. This documentation walks you through installation, customizing settings, and restricting access to the docs. ### Method N/A (This is a description of a plugin, not a specific endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### GET /count Source: https://docs.strapi.io/cms/admin-panel-customization/homepage Retrieves the counts of all content types available in the Strapi application. It iterates through registered content types, filters for those starting with 'api::', and uses the Document Service to count entities for each. ```APIDOC ## GET /count ### Description Retrieves the counts of all content types available in the Strapi application. It iterates through registered content types, filters for those starting with 'api::', and uses the Document Service to count entities for each. ### Method GET ### Endpoint /count ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **object** - An object where keys are content type display names or UIDs, and values are their respective entity counts. #### Response Example ```json { "Product": 50, "Article": 120, "Page": 30 } ``` ``` -------------------------------- ### Strapi Top-Level Getter Examples (JavaScript) Source: https://docs.strapi.io/assets/files/llms-full-e8ba8b5875941be5a32e24360def8055 Provides examples of using Strapi's top-level getters to access various plugin components such as configuration, routes, controllers, services, content types, policies, and middlewares. This syntax is useful for structured access within plugin code. ```javascript strapi.plugin('plugin-name').config strapi.plugin('plugin-name').routes strapi.plugin('plugin-name').controller('controller-name') strapi.plugin('plugin-name').service('service-name') strapi.plugin('plugin-name').contentType('content-type-name') strapi.plugin('plugin-name').policy('policy-name') strapi.plugin('plugin-name').middleware('middleware-name') ``` -------------------------------- ### Implement Strapi Services in JavaScript and TypeScript Source: https://docs.strapi.io/cms/backend-customization/services Demonstrates how to manually create and implement services in Strapi using JavaScript and TypeScript. This includes creating entirely new custom services, wrapping core services to add custom logic, and replacing core services entirely. These services are placed in `./src/api/[api-name]/services/` or `./src/plugins/[plugin-name]/services/`. ```javascript const { createCoreService } = require('@strapi/strapi').factories; module.exports = createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ // Method 1: Creating an entirely new custom service async exampleService(...args) { let response = { okay: true } if (response.okay === false) { return { response, error: true } } return response }, // Method 2: Wrapping a core service (leaves core logic in place) async find(...args) { // Calling the default core controller const { results, pagination } = await super.find(...args); // some custom logic results.forEach(result => { result.counter = 1; }); return { results, pagination }; }, // Method 3: Replacing a core service async findOne(documentId, params = {}) { return strapi.documents('api::restaurant.restaurant').findOne(documentId, this.getFetchParams(params)); } })); ``` ```typescript import { factories } from '@strapi/strapi'; export default factories.createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ // Method 1: Creating an entirely custom service async exampleService(...args) { let response = { okay: true } if (response.okay === false) { return { response, error: true } } return response }, // Method 2: Wrapping a core service (leaves core logic in place) async find(...args) { // Calling the default core controller const { results, pagination } = await super.find(...args); // some custom logic results.forEach(result => { result.counter = 1; }); return { results, pagination }; }, // Method 3: Replacing a core service async findOne(documentId, params = {}) { return strapi.documents('api::restaurant.restaurant').findOne(documentId, this.getFetchParams(params)); } })); ``` -------------------------------- ### TypeScript server.js Configuration (distDir) Source: https://docs.strapi.io/cms/deployment Note for TypeScript projects: the 'distDir' option must be provided when starting the server. Consult the TypeScript documentation for details on this configuration. -------------------------------- ### Build Strapi Plugin for Publishing Source: https://docs.strapi.io/llms-full Prepares a Strapi plugin for distribution by building its assets and verifying its integrity. This command ensures the plugin is optimized and ready for deployment to NPM or the Strapi Marketplace. ```bash cd ../my-strapi-plugin yarn build ``` -------------------------------- ### Configure Windows Build Script Source: https://docs.strapi.io/cms/deployment Instructions to install the 'cross-env' package and configure a Windows-specific build script in package.json. This allows setting the NODE_ENV variable for Windows. ```shell npm install cross-env ``` ```json "build:win": "cross-env NODE_ENV=production npm run build" ``` ```shell npm run build:win ``` -------------------------------- ### Strapi TypeScript Configuration Source: https://docs.strapi.io/llms Provides guidance on integrating TypeScript into a Strapi application. This includes setup instructions and examples for leveraging TypeScript's features for type safety and improved development experience. ```typescript // Example: src/api/article/content-types/article/index.ts import { Schema, Attribute } from '@strapi/strapi'; const schema: Schema.ContentType = { kind: 'collectionType', collectionName: 'articles', info: { singularName: 'article', pluralName: 'articles', displayName: 'Article', }, options: { draftAndPublish: true, }, attributes: { title: { type: 'string', required: true, }, content: { type: 'richtext', }, author: { type: 'relation', relation: 'oneToOne', target: 'plugin::users-permissions.user', }, }, }; export default schema; ``` ```typescript // Example: src/types/generated.d.ts (auto-generated or manual) declare namespace Strapi { interface Components { // ... your component types } interface ContentTypes { 'api::article.article': { id: number; title: string; content: string | null; author: Strapi.Models.User | null; // ... other attributes }; // ... other content types } interface Models { User: { id: number; username: string; email: string; // ... other user attributes }; } } ``` -------------------------------- ### Initialize New Strapi Plugin using npx @strapi/sdk-plugin Source: https://docs.strapi.io/cms/plugins-development/plugin-sdk Creates a new Strapi plugin at a specified path. This command is the starting point for developing a new plugin. It accepts a 'path' argument to define the plugin's location and supports a '--debug' flag for verbose logging. ```bash npx @strapi/sdk-plugin init ``` -------------------------------- ### Postman Local Authentication Setup Source: https://docs.strapi.io/cms/features/users-permissions Provides instructions for setting up local authentication in Postman. It specifies configuring the request body as 'raw' with 'JSON' data format and includes an example JSON payload. ```json { "identifier": "user@strapi.io", "password": "strapiPassword" } ``` -------------------------------- ### Strapi Help: List Available CLI Commands Source: https://docs.strapi.io/assets/files/llms-full-e8ba8b5875941be5a32e24360def8055 The `strapi help` command provides a list of all available Strapi CLI commands. This is useful for discovering functionalities and understanding how to interact with the Strapi project from the command line. ```bash strapi help ``` -------------------------------- ### Full Strapi Server Configuration Example (TypeScript) Source: https://docs.strapi.io/cms/configurations/server A comprehensive TypeScript configuration for the Strapi server, mirroring the detailed JavaScript example. It covers advanced settings like socket configuration, error emission, public URL, proxy, cron, and logging, providing a robust setup option for TypeScript projects. ```typescript export default ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array('APP_KEYS'), }, socket: '/tmp/nginx.socket', // only use if absolutely required emitErrors: false, url: env('PUBLIC_URL', 'https://api.example.com'), proxy: { koa: env.bool('IS_PROXIED', true) }, cron: { enabled: env.bool('CRON_ENABLED', false), }, transfer: { remote: { enabled: false, }, }, logger: { updates: { enabled: false, }, startup: { enabled: false, }, }, }); ```