Merge branch 'master' into admin-russian-translation

This commit is contained in:
Sulakin Vadim 2019-11-27 16:42:01 +03:00 committed by GitHub
commit 9899480562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 524 additions and 278 deletions

View File

@ -186,9 +186,12 @@ module.exports = {
'/3.0.0-beta.x/guides/update-version',
'/3.0.0-beta.x/guides/databases',
'/3.0.0-beta.x/guides/deployment',
'/3.0.0-beta.x/guides/process-manager',
'/3.0.0-beta.x/guides/jwt-validation',
'/3.0.0-beta.x/guides/error-catching',
'/3.0.0-beta.x/guides/external-data',
'/3.0.0-beta.x/guides/custom-data-response',
'/3.0.0-beta.x/guides/custom-admin',
'/3.0.0-beta.x/guides/slug',
'/3.0.0-beta.x/guides/webhooks',
],

View File

@ -215,17 +215,17 @@ You can access the config of the current environment through `strapi.config.curr
- `timezone` (string): Set the default behavior for local time. Default value: `utc`.
- `schema` (string): Set the default database schema. **Used only for Postgres DB**
- `ssl` (boolean): For ssl database connection.
- `options` Options used for database connection.
- `debug` (boolean): Show database exchanges and errors.
- `autoMigration` (boolean): To disable auto tables/columns creation for SQL database.
- `pool` Options used for database connection pooling. For more information look at [Knex's pool config documentation](https://knexjs.org/#Installation-pooling).
- `min` (integer): Minimum number of connections to keep in the pool. Default value: `0`.
- `max` (integer): Maximum number of connections to keep in the pool. Default value: `10`.
- `acquireTimeoutMillis` (integer): Maximum time in milliseconds to wait for acquiring a connection from the pool. Default value: `2000` (2 seconds).
- `createTimeoutMillis` (integer): Maximum time in milliseconds to wait for creating a connection to be added to the pool. Default value: `2000` (2 seconds).
- `idleTimeoutMillis` (integer): Number of milliseconds to wait before destroying idle connections. Default value: `30000` (30 seconds).
- `reapIntervalMillis` (integer): How often to check for idle connections in milliseconds. Default value: `1000` (1 second).
- `createRetryIntervalMillis` (integer): How long to idle after a failed create before trying again in milliseconds. Default value: `200`.
- `options` Options used for database connection.
- `debug` (boolean): Show database exchanges and errors.
- `autoMigration` (boolean): To disable auto tables/columns creation for SQL database.
- `pool` Options used for database connection pooling. For more information look at [Knex's pool config documentation](https://knexjs.org/#Installation-pooling).
- `min` (integer): Minimum number of connections to keep in the pool. Default value: `0`.
- `max` (integer): Maximum number of connections to keep in the pool. Default value: `10`.
- `acquireTimeoutMillis` (integer): Maximum time in milliseconds to wait for acquiring a connection from the pool. Default value: `2000` (2 seconds).
- `createTimeoutMillis` (integer): Maximum time in milliseconds to wait for creating a connection to be added to the pool. Default value: `2000` (2 seconds).
- `idleTimeoutMillis` (integer): Number of milliseconds to wait before destroying idle connections. Default value: `30000` (30 seconds).
- `reapIntervalMillis` (integer): How often to check for idle connections in milliseconds. Default value: `1000` (1 second).
- `createRetryIntervalMillis` (integer): How long to idle after a failed create before trying again in milliseconds. Default value: `200`.
:::
@ -242,10 +242,10 @@ You can access the config of the current environment through `strapi.config.curr
- `database` (string): Database name.
- `username` (string): Username used to establish the connection.
- `password` (string): Password used to establish the connection.
- `options` Options used for database connection.
- `ssl` (boolean): For ssl database connection.
- `debug` (boolean): Show database exchanges and errors.
- `authenticationDatabase` (string): Connect with authentication.
- `options` Options used for database connection.
- `ssl` (boolean): For ssl database connection.
- `debug` (boolean): Show database exchanges and errors.
- `authenticationDatabase` (string): Connect with authentication.
:::
@ -314,7 +314,7 @@ You can access the config of the current environment through `strapi.config.curr
{
"defaultConnection": "default",
"connections": {
"sqlite": {
"default": {
"connector": "strapi-hook-bookshelf",
"settings": {
"client": "sqlite",
@ -481,7 +481,7 @@ As an example using this configuration with Nginx your server would respond to `
For security reasons, sometimes it's better to set variables through the server environment. It's also useful to push dynamics values into configurations files. To enable this feature into JSON files, Strapi embraces a JSON-file interpreter into his core to allow dynamic value in the JSON configurations files.
### Syntax
#### Syntax
The syntax is inspired by the [template literals ES2015 specifications](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). These dynamic values are indicated by the Dollar sign and curly braces (`${expression}`).

View File

@ -66,9 +66,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :---------------------------------------------- | :----------------------------------- |
| GET | [/{content-type}](#get-restaurants) | Get a list of {content-type} entries |
| GET | [/{content-type}/:id](#get-restaurants-id) | Get a specific {content-type} entry |
| GET | [/{content-type}/count](#get-restaurants-count) | Count {content-type} entries |
| POST | [/{content-type}](#post-restaurants) | Create a {content-type} entry |
| GET | [/{content-type}/:id](#get-restaurants-id) | Get a specific {content-type} entry |
| DELETE | [/{content-type}/:id](#delete-restaurants-id) | Delete a {content-type} entry |
| PUT | [/{content-type}/:id](#put-restaurants-id) | Update a {content-type} entry |
@ -87,9 +87,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :----------------- | :------------------------ |
| GET | /restaurants | Get a list of restaurants |
| GET | /restaurants/:id | Get a specific restaurant |
| GET | /restaurants/count | Count restaurants |
| POST | /restaurants | Create a restaurant |
| GET | /restaurants/:id | Get a specific restaurant |
| DELETE | /restaurants/:id | Delete a restaurant |
| PUT | /restaurants/:id | Update a restaurant |
@ -106,9 +106,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :-------------- | :--------------------- |
| GET | /articles | Get a list of articles |
| GET | /articles/:id | Get a specific article |
| GET | /articles/count | Count articles |
| POST | /articles | Create a article |
| GET | /articles/:id | Get a specific article |
| DELETE | /articles/:id | Delete a article |
| PUT | /articles/:id | Update a article |
@ -125,9 +125,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :-------------- | :--------------------- |
| GET | /products | Get a list of products |
| GET | /products/:id | Get a specific product |
| GET | /products/count | Count products |
| POST | /products | Create a product |
| GET | /products/:id | Get a specific product |
| DELETE | /products/:id | Delete a product |
| PUT | /products/:id | Update a product |
@ -144,9 +144,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :---------------- | :----------------------- |
| GET | /categories | Get a list of categories |
| GET | /categories/:id | Get a specific category |
| GET | /categories/count | Count categories |
| POST | /categories | Create a category |
| GET | /categories/:id | Get a specific category |
| DELETE | /categories/:id | Delete a category |
| PUT | /categories/:id | Update a category |
@ -163,9 +163,9 @@ Here is the list of endpoints generated for each of your **Content Types**
| Method | Path | Description |
| :----- | :---------- | :----------------- |
| GET | /tags | Get a list of tags |
| GET | /tags/:id | Get a specific tag |
| GET | /tags/count | Count tags |
| POST | /tags | Create a tag |
| GET | /tags/:id | Get a specific tag |
| DELETE | /tags/:id | Delete a tag |
| PUT | /tags/:id | Update a tag |
@ -210,6 +210,38 @@ GET http://localhost:1337/restaurants
]
```
## Get an entry
Returns an entry by id.
**Example request**
```js
GET http://localhost:1337/restaurants/1
```
**Example response**
```json
{
"id": 1,
"title": "Restaurant 1",
"cover": {
"id": 1,
"url": "/uploads/3d89ba92f762433bbb75bbbfd9c13974.png"
//...
},
"opening_hours": [
{
"id": 1,
"day_interval": "Tue - Sat",
"opening_hour": "7:30 PM",
"closing_hour": "10:00 PM"
}
]
}
```
## Count entries
Returns the count of entries matching the query filters. You can read more about parameters [here](./parameters.md).
@ -272,38 +304,6 @@ POST http://localhost:1337/restaurants
}
```
## Get an entry
Returns an entry by id.
**Example request**
```js
GET http://localhost:1337/restaurants/1
```
**Example response**
```json
{
"id": 1,
"title": "Restaurant 1",
"cover": {
"id": 1,
"url": "/uploads/3d89ba92f762433bbb75bbbfd9c13974.png"
//...
},
"opening_hours": [
{
"id": 1,
"day_interval": "Tue - Sat",
"opening_hour": "7:30 PM",
"closing_hour": "10:00 PM"
}
]
}
```
## Update an entry
Partially updates an entry by id and returns its value.

View File

@ -55,6 +55,14 @@ If you use the same operator (except for in and nin) the values will be used to
`GET /restaurants?name_contains=pizza&name_contains=giovanni`
::: warning
If you want to use `AND` for your query you will have to create a custom query by using the [Query](../concepts/query.md) documentation.
Strapi doesn't support the `AND` opperator for now.
:::
## Deep filtering
Find restaurants owned by a chef who belongs to a restaurant with star equal to 5

View File

@ -1,127 +1,27 @@
# Installation Requirements
# Installation requirements
This page covers installing the basic requirements for Strapi.
## Basic Installation Requirements
## Node.js
Strapi only requires [Node.js](https://nodejs.org). The current recommended version to run strapi is `Node v10` (current `LTS`).
This is all that is needed before Strapi can run on your local environment.
## Installing Node.js
You can also use **yarn** if you want [here](https://yarnpkg.com/en/docs/getting-started) are the instructions to get started with it.
You can install `Node.js` and `npm` for `Windows 10`, `Ubuntu 18.04` and `Mac O/S Mojave` with the following instructions.
- **Node.js** >= 10.x
- **NPM** >= 6.x
#### Installation Instructions for each Operating System:
## Databases
:::: tabs
Strapi is supporting multiple databases. If you are using the `--quickstart` or if you manually chose the `SQLite` database, you will not need to install any database on you local computer.
::: tab "Windows 10"
If you want to use a custom database, here is versions you will have to respect:
### Installing Node.js on Windows 10
There are several methods to install Node.js on _Windows 10_.
We will follow the most common download and installation procedure. These _instructions are for Windows 10_. (If you are installing on a different version of Windows or if you have trouble following these instructions, please review the [official Node.js documentation](https://nodejs.org/en/docs/).)
1. Download the Windows Installer from the [downloads page](https://nodejs.org/en/download/). You will need to choose the 32-bit or 64-bit version. We recommend the LTS (long-term support) version of Node.js.
2. Double-click the node-v10.x.x-x86.msi file icon. Click "Next" for the default options and to install Node.js under the recommended and most common settings. After clicking "Next" several times, click "Install" to install Node.js. When it is done installing, click "Finish".
3. Verify both Node.js and npm have installed correctly. Open your Command Prompt:
- Click your Start Button
- In Search type, "cmd"
- Then click on "Command Prompt".
- Type the following commands in your Command Prompt
Verify Node.js has correctly installed:
```shell
node -v
## You should see "v10.x.x
```
Next, verify npm has correctly installed:
```shell
npm -v
## You should see "6.x.x"
```
:::
::: tab "Mac O/S"
### Installing Node.js on Mac O/S X (Mojave)
There are multiple methods to install Node.js on _Mac O/S X (Mojave)_.
We will follow the most common download and installation procedure. _These instructions are for Mac O/S X (Mojave)_. (If you are installing on a different version of Mac O/S or if you have trouble following these instructions, please review the [official Node.js documentation](https://nodejs.org/en/docs/).)
1. Download the Mac O/S Installer from the [downloads page](https://nodejs.org/en/download/). We recommend the LTS (long-term support) version of Node.js.
2. Launch the node-v10.x.x.pkg file icon. Click "Continue" for the default options and to install Node.js under the recommended and most common settings. After clicking "Continue" several times, click "Install" to install Node.js. When it is done installing, click "Close".
3. Verify both Node.js and npm have installed correctly. Open your terminal prompt:
- Open your Applications folder
- Find and open the Utilities folder
- Find "Terminal" and click on it to open it.
- Type the following commands in your Terminal
Verify Node.js has correctly installed:
```terminal
node -v
## You should see "v10.x.x"
```
Next, verify npm has correctly installed:
```terminal
npm -v
## You should see "6.x.x"
```
:::
::: tab "UBUNTU 18.04"
### Installing Node.js on Ubuntu 18.04
There are multiple methods to install Node.js on _Ubuntu 18.04_.
We will follow the most common download and installation procedure. _These instructions are for Ubuntu 18.04_. (If you are installing on a different version of Ubuntu or a different Linux Distro or if you have trouble following these instructions, please review the [official Node.js documentation](https://nodejs.org/en/docs/).)
1. Install cURL and use cURL to download the Node.js (with npm) source code
```bash
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
```
2. Install Node.js (with npm) and install `build-essential` package:
```bash
sudo apt-get install -y nodejs
sudo apt install build-essential
```
Verify Node.js has correctly installed:
```bash
node -v
## You should see "v10.x.x"
```
Next, verify npm has correctly installed:
```bash
npm -v
## You should see "6.x.x"
```
:::
::::
### Using Yarn
You can also use yarn if you want [here](https://yarnpkg.com/en/docs/getting-started) are the instructions to get started with it.
- **MongoDB** >= 3.6
- **MySQL** >= 5.6
- **MariaDB** >= 10.1
- **PostgreSQL** >= 10
- **SQLite** >= 3
::: tip NEXT STEPS
👏 Congrats, you are all set! Now that Node.js is installed you can continue with the [Quick start guide](quick-start.md).

View File

@ -10,7 +10,7 @@ By following this tutorial, you install and create your first Strapi project.
::: tip NOTE
You need to have **_Node.js and npm_** installed on your system before following these steps. If you do not have Node.js and npm installed (or are not sure), please visit our [Installation Requirements](install-requirements.md).
You need to have **_Node.js and npm_** installed on your system before following these steps. If you do not have Node.js and npm installed (or are not sure), please visit our [installation requirements](install-requirements.md).
:::
@ -20,31 +20,41 @@ You need to have **_Node.js and npm_** installed on your system before following
## 1. Install Strapi and create a project
- Navigate to your parent `Projects/` directory from your command line.
Navigate to your parent `Projects/` directory from your command line.
**Note:** In this tutorial, the example assumes a **Projects** folder on your **Desktop**. However, this is not required, and you may put your project where you want.
::: tip NOTE
Path: `~/Desktop/Projects/`
In this tutorial, the example assumes a **Projects** folder on your **Desktop**. However, this is not required, and you may put your project where you want.
Use **only one** of the following commands to create a new Strapi project:
:::
---
**Path —** `~/Desktop/Projects/`
- Use **yarn** to install the Strapi project (**recommended**). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/)
Use **only one** of the following commands to create a new Strapi project
:::: tabs
::: tab yarn
Use **yarn** to install the Strapi project (**recommended**). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/)
```bash
yarn create strapi-app my-project --quickstart
```
**or**
:::
- Use **npm/npx** to install the Strapi project
::: tab npx
Use **npm/npx** to install the Strapi project
```bash
npx create-strapi-app my-project --quickstart
```
---
:::
::::
The command creates a Strapi project `my-project/` folder within your parent `Projects/` directory.
@ -52,9 +62,6 @@ The command creates a Strapi project `my-project/` folder within your parent `Pr
When you create a new Quick Start(`--quickstart`) project, Strapi downloads the node modules and the Strapi files needed. Using `--quickstart` automatically completes an **additional** step of **building the administration panel** for Strapi and then **starting** Strapi for you. This opens the browser for you and brings you to the [Welcome](http://localhost:1337/admin/plugins/users-permissions/auth/register) page.
:::
::: tip NOTE
You can replace the `my-project` name with any name you want. E.g., `yarn create strapi-app my-foodadvisor-project --quickstart` creates a folder `./Projects/my-foodadvisor-project`.
:::
@ -131,9 +138,7 @@ Building your admin UI with development configuration ...
::: tip NOTE
Using the `--quickstart` flag installs Strapi using an [SQLite](https://www.sqlite.org/index.html) database. You may, at any time, leave off the **--flag**, but you need to follow a few configuration steps for your database choice. **You need to have your database choice installed and running locally before creating your project.**
**Note:** An **SQLite** database is an excellent database to use for prototyping and _developing_ Strapi projects. **SQLite** is a light database that ports effortlessly to the other relational databases (**MySQL**, **PostgreSQL**, and **MariaDB**). It is recommended to **develop** with SQLite and to use another relational database (MySQL, PostgreSQL or MariaDB) in production.
**Note:** If you would like to use **MongoDB** in production, you need to [install, run, and use MongoDB to develop your Strapi project (in development)](../guides/databases.md#mongodb-installation).
If you would like to use **MongoDB** in production, you need to [install, run, and use MongoDB to develop your Strapi project (in development)](../guides/databases.md#mongodb-installation).
:::
You are now ready to create a new **Administrator** and new front-end **User**.
@ -164,7 +169,11 @@ After your **Administrator** registration is complete, you see the Strapi _Admin
Up until this point, you have created an **Administrator**, and so you next want to create a front-end **User**.
**Note:** It is not necessary to always create a front-end **User** for your **Administrators**; in this case, the **Administrator** is also a front-end **User** as an "Author" of content in the application.
::: tip NOTE
It is not necessary to always create a front-end **User** for your **Administrators**; in this case, the **Administrator** is also a front-end **User** as an "Author" of content in the application.
:::
- Click on `Users` located under **CONTENT TYPES** in the left-hand menu
- Click the blue **+ Add New User** button in the top right corner
@ -193,7 +202,7 @@ Additional **Restaurant** themed **Content Types** and fields can be seen in the
### The Restaurant Content Type
- Go to the **Content Type Builder** plugin, located in the left menu: Under **PLUGINS**: --> **Content Type Builder**
Go to the **Content Type Builder** plugin, located in the left menu: Under **PLUGINS** -> **Content Type Builder**
You are now able to see the three available **Content Types**. At this point, three Content Types are available `Permission`, `Role`, and `Users`.
@ -201,7 +210,7 @@ You are now able to see the three available **Content Types**. At this point, th
You need to create a new **Content Type** for `Restaurants`.
1. Complete these steps to **Add a Restaurant Content Type**:
1. Complete these steps to **Add a Restaurant Content Type**
- Click the `+ Add A Content Type` link (under existing **CONTENT TYPES**)
- Enter a **Name** for your new **Content Type** (call this `restaurant`), and you can write `Restaurant Listings` for the **Description**
@ -215,7 +224,7 @@ The Content Type **Name** is always **singular**. For example, `restaurant` not
:::
2. You are now at the **Field Selection** panel:
2. You are now at the **Field Selection** panel
You may add your first field, a **String** field for the **Restaurant** name.
@ -402,7 +411,11 @@ You are now ready to add a third field, another **String** field for the **Closi
After Strapi has restarted, you are ready to assign this **Hours_of_operation** group to the **Restaurant** Content Type.
**Note:** It would be possible to assign the **Hours_of_operation** group to another **Content Type**, let's say, a **Cafe** Content Type. You have the option to reuse this group across your application.
::: tip NOTE
It would be possible to assign the **Hours_of_operation** group to another **Content Type**, let's say, a **Cafe** Content Type. You have the option to reuse this group across your application.
:::
3. Next, you need to assign the **Hours_of_operation** Group to the **Restaurant** Content Type.

View File

@ -12,18 +12,26 @@ _For a step-by-step guide, please take a look at the [detailed tutorial](quick-s
## 1. Install Strapi and Create a new project
:::: tabs
::: tab yarn
```bash
yarn create strapi-app my-project --quickstart
```
**or**
:::
- Use **npm/npx** to install the Strapi project.
::: tab npx
```bash
npx create-strapi-app my-project --quickstart
```
:::
::::
## 2. Create an Administrator user
Navigate to [**http://localhost:1337/admin**](http://localhost:1337/admin).

View File

@ -0,0 +1,114 @@
# Custom admin
In this guide we will see how you can customize the admin panel.
## Introduction
For this example, we will see two things, the first one will be the customization of the admin panel itself, by updating the content of the `/admin/` home page. And in a second time we will see ho to update the interface of a plugin, by replacing the `date` format in the content manager list view.
First of all, you will have to read the [customization concept](../concepts/customization.md), it will help you to understand how to customize all your application.
## Update the admin home page
If you are following the customization concept, you can already create a `./admin` folder in your application.
### Target the file to update
Then you will have to investigate into the [`strapi-admin`](https://github.com/strapi/strapi/tree/master/packages/strapi-admin) package to find the file that is used to display the admin panel home page.
Here is the [HomePage container](https://github.com/strapi/strapi/tree/master/packages/strapi-admin/admin/src/containers/HomePage/index.js) you will have to update.
### Eject the file
Let's eject this file to be able to customize it.
**Path —** `./admin/src/containers/HomePage/index.js`
In this new file, paste the current [HomePage container](https://github.com/strapi/strapi/tree/master/packages/strapi-admin/admin/src/containers/HomePage/index.js) code.
To run your application, you will have to run the `yarn develop --watch-admin` command.
If you visit the admin, nothing will have changed in the home page. And it's normal!
### Customize the file
To keep this example really simple, we will just reduce the HomePage in it's more simple design.
**Path —** `./admin/src/containers/HomePage/index.js`
```js
import React, { memo } from 'react';
import { Block, Container } from './components';
const HomePage = ({ global: { plugins }, history: { push } }) => {
return (
<>
<Container className="container-fluid">
<div className="row">
<div className="col-12">
<Block>Hello World!</Block>
</div>
</div>
</Container>
</>
);
};
export default memo(HomePage);
```
Now the admin panel home page should just contain the sentence `Hello Wold!`.
## Update the Content Manager
If you are following the customization concept, you can already create a `./extensions/content-manager` folder in your application.
::: tip
To be able to see the update, you will need to have a Content Type that have a `date` attribute.
:::
### Target the file to update
Then you will have to investigate into the [`strapi-plugin-content-manager`](https://github.com/strapi/strapi/tree/master/packages/strapi-plugin-content-manager) package to find the file that is used to format the date for the list view.
Here is the [Row component](https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js) you will have to update.
### Eject the file
Let's eject the file to be able to customize it.
**Path —** `./extensions/content-manager/admin/src/components/CustomTable/Row.js`
In this new file, paste the current [Row component](https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js) code.
To run your application, you will have to run the `yarn develop --watch-admin` command.
If you visit the entry list view of your content type, nothing will have changed. And it's normal!
### Customize the file
In our example, we want to change the format of the date. We have to find in this file the line that manage the date format.
Here is the code you have to find:
```js
return moment
.parseZone(date)
.utc()
.format('dddd, MMMM Do YYYY');
```
Now let's replace `.format('dddd, MMMM Do YYYY');` by `.format('YYYY/MM/DD');`
And tada, the date will now display with the new format.
## Build the new admin
Well now you have the admin panel you want. But during all the process, the admin panel was updated on the run time because of the command `yarn develop --watch-admin`.
If you start your application using `yarn start` or `yarn develop` the admin will be the old version. Your updates are not applied.
To do so, you have to build the admin panel using the following command `yarn build`.

View File

@ -0,0 +1,117 @@
# Custom data response
In this guide we will see how you can customize your API's response..
## Introduction
To be able to update the default data response you have first to understand how it works.
When you create a content type, it generates an API with the following list of [endpoints](../content-api/endpoint).
Each of these endpoint triggers a controller action. Here is the list of [controller actions](../concepts/controller.md) that exist by default when a content type is created.
If you check the controller file of your generated API `./api/{content-type}/controller/{Content-Type}.js`, you will see an empty file. It is because all the default logic is managed by Strapi. But you can override these actions with your own code.
And that is what we will do to manage our custom data response.
## Example
In our example we will use a restaurant type with a chef.. By default when you fetch restaurants, you will got all information of the chef.
Let's consider you don't want to expose the chef's email for privacy reasons.
To enforce this rule we will customize the action that fetchs all restaurants and remove the email from the returned data.
To follow the example your will have to create a content type `restaurant` and add the following field definition:
- `string` attribute named `name`
- `text` attribute named `description`
- `relation` attribute **Restaurant** (`chef`) - **User** has many **Restaurants** - **Users** (`restaurants`)
Then add some data.
## Override controller action
To customize the function that fetch all our restaurants we will have to override the `find` function.
First, to see the difference, let's request `GET /restaurants`. You will see all the data you created.
Now let's start the customization.
**Path —** `./api/restaurant/controller/Restaurant.js`
```js
module.exports = {
async find() {
return 'strapi';
},
};
```
After saving the new function, let's restart the `GET /restaurants` request. We will see `strapi` as response.
## Get the data back
We now know the function we have to update, but we just want to customize the returned restaurant values.
In the [controller documentation](../concepts/controllers.html#extending-a-model-controller) you will find the default implementation of every actions. It will help you overwrite the fetch logic.
**Path —** `./api/restaurant/controller/Restaurant.js`
```js
const { sanitizeEntity } = require('strapi-utils');
module.exports = {
async find(ctx) {
let entities;
if (ctx.query._q) {
entities = await strapi.services.restaurant.search(ctx.query);
} else {
entities = await strapi.services.restaurant.find(ctx.query);
}
return entities.map(entity =>
sanitizeEntity(entity, { model: strapi.models.restaurant })
);
},
};
```
And now the data is back on `GET /restaurants`
## Apply our changes
We can see the `find` function returns the result of the `map`. And the map function just sanitizes all entries.
So instead of just return the sanitized entry, we will also remove the chef email of each restaurant.
**Path —** `./api/restaurant/controller/Restaurant.js`
```js
const { sanitizeEntity } = require('strapi-utils');
module.exports = {
async find(ctx) {
let entities;
if (ctx.query._q) {
entities = await strapi.services.restaurant.search(ctx.query);
} else {
entities = await strapi.services.restaurant.find(ctx.query);
}
return entities.map(entity => {
const restaurant = sanitizeEntity(entity, {
model: strapi.models.restaurant,
});
if (restaurant.chef && restaurant.chef.email) {
delete restaurant.chef.email;
}
return restaurant;
});
},
};
```
And tada! The email disapeared.
::: tip
This guide can be applied to any other controller action.
:::

View File

@ -3,7 +3,7 @@
Strapi gives you the option to choose the most appropriate database for your project. It currently supports **PostgreSQL**, **MongoDB**, **SQLite**, **MySQL** and
**MariaDB**. The following documentation covers how to install these databases locally (for development purposes) and on various hosted or cloud server solutions (for staging or production purposes).
:::note
::: tip
Deploying **Strapi** itself is covered in the [Deployment Guide](deployment.md).
:::
@ -20,7 +20,7 @@ Simply use one of the following commands.
::: tab yarn
```bash
yarn create strapi-app new my-project --quickstart
yarn create strapi-app my-project --quickstart
```
:::

View File

@ -995,7 +995,7 @@ npm install pm2@latest -g
### The ecosystem.config.js file
- You will need to configure an `ecosystem.config.js` file. This file will manage the **database connection variables** Strapi needs to connect to your database. The `ecosystem.config.js` will also be used by `pm2` to restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/).
- You will need to configure an `ecosystem.config.js` file. This file will manage the **database connection variables** Strapi needs to connect to your database. The `ecosystem.config.js` will also be used by `pm2` to restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/).
- You will need to open your `nano` editor and then `copy/paste` the following:

View File

@ -0,0 +1,83 @@
---
sidebarDepth: 2
---
# Process manager
In this guide we will see how you can start a Strapi application using a process manager.
::: tip
In this example we will use [PM2](https://pm2.keymetrics.io/).
:::
## Install PM2
PM2 allows you to keep your Strapi project alive and to reload it without downtime.
You will install PM2 globally
:::: tabs
::: tab yarn
`yarn global add pm2`
:::
::: tab npm
`npm install pm2 -g`
:::
::::
## Basic usage
### Starting with server.js file
The basic usage to start an application with PM2 will be to run a command like this `pm2 start server.js`.
But here we are facing an issue. In your project you don't have a `.js` file to run your Strapi application.
So first let's create a `server.js` file that will let you run the `pm2` command.
**Path —** `./server.js`
```js
const strapi = require('strapi');
strapi().start();
```
Now you will be able to start your server by running `pm2 start server.js`.
### Starting with strapi command
By default there is two important commands.
- `yarn develop` to start your project in development mode.
- `yarn start` to start your app for production.
You can also start your process manager using the `yarn start` command.
`pm2 start npm --name app -- run start`
## Configuration file
PM2 lets you create a config file to save all information to start your server properly at anytime.
By running `pm2 init` it will init an `ecosystem.config.js` in your application.
Then replace the content of this file by the following code.
```js
module.exports = {
apps: [
{
name: 'app',
script: 'npm',
args: 'start',
},
],
};
```
And then run `pm2 start ecosystem.config.js` to start the pm2 process.
You can see the full documentation of available configuration in the [PM2 ecosystem file documentation](https://pm2.keymetrics.io/docs/usage/application-declaration/).

View File

@ -1,7 +1,7 @@
{
"name": "getstarted",
"private": true,
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "A Strapi application.",
"scripts": {
"develop": "strapi develop",
@ -15,22 +15,22 @@
"mysql": "^2.17.1",
"pg": "^7.10.0",
"sqlite3": "^4.0.6",
"strapi": "3.0.0-beta.17.5",
"strapi-admin": "3.0.0-beta.17.5",
"strapi-hook-bookshelf": "3.0.0-beta.17.5",
"strapi-hook-knex": "3.0.0-beta.17.5",
"strapi-hook-mongoose": "3.0.0-beta.17.5",
"strapi-middleware-views": "3.0.0-beta.17.5",
"strapi-plugin-content-manager": "3.0.0-beta.17.5",
"strapi-plugin-content-type-builder": "3.0.0-beta.17.5",
"strapi-plugin-documentation": "3.0.0-beta.17.5",
"strapi-plugin-email": "3.0.0-beta.17.5",
"strapi-plugin-graphql": "3.0.0-beta.17.5",
"strapi-plugin-upload": "3.0.0-beta.17.5",
"strapi-plugin-users-permissions": "3.0.0-beta.17.5",
"strapi-provider-email-mailgun": "3.0.0-beta.17.5",
"strapi-provider-upload-aws-s3": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5"
"strapi": "3.0.0-beta.17.6",
"strapi-admin": "3.0.0-beta.17.6",
"strapi-hook-bookshelf": "3.0.0-beta.17.6",
"strapi-hook-knex": "3.0.0-beta.17.6",
"strapi-hook-mongoose": "3.0.0-beta.17.6",
"strapi-middleware-views": "3.0.0-beta.17.6",
"strapi-plugin-content-manager": "3.0.0-beta.17.6",
"strapi-plugin-content-type-builder": "3.0.0-beta.17.6",
"strapi-plugin-documentation": "3.0.0-beta.17.6",
"strapi-plugin-email": "3.0.0-beta.17.6",
"strapi-plugin-graphql": "3.0.0-beta.17.6",
"strapi-plugin-upload": "3.0.0-beta.17.6",
"strapi-plugin-users-permissions": "3.0.0-beta.17.6",
"strapi-provider-email-mailgun": "3.0.0-beta.17.6",
"strapi-provider-upload-aws-s3": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6"
},
"strapi": {
"uuid": "getstarted"

View File

@ -1,5 +1,5 @@
{
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"packages": [
"packages/*",
"examples/*"

View File

@ -1,6 +1,6 @@
{
"name": "create-strapi-app",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a new Strapi application.",
"license": "MIT",
"homepage": "http://strapi.io",
@ -21,7 +21,7 @@
],
"dependencies": {
"commander": "^2.20.0",
"strapi-generate-new": "3.0.0-beta.17.5"
"strapi-generate-new": "3.0.0-beta.17.6"
},
"scripts": {
"test": "echo \"no tests yet\""

View File

@ -1,6 +1,6 @@
{
"name": "strapi-admin",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Strapi Admin",
"repository": {
"type": "git",
@ -69,8 +69,8 @@
"reselect": "^3.0.1",
"sanitize.css": "^4.1.0",
"shelljs": "^0.7.8",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6",
"style-loader": "^0.23.1",
"styled-components": "^4.2.0",
"terser-webpack-plugin": "^1.2.3",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-api",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate an API for a Strapi application.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-controller",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a controller for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-model",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a model for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-new",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a new Strapi application.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-plugin",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate an plugin for a Strapi application.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-policy",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a policy for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate-service",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Generate a service for a Strapi API.",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-generate",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Master of ceremonies for the Strapi generators.",
"homepage": "http://strapi.io",
"keywords": [
@ -20,7 +20,7 @@
"fs-extra": "^8.0.1",
"lodash": "^4.17.11",
"reportback": "^2.0.2",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-utils": "3.0.0-beta.17.6"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-helper-plugin",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Helper for Strapi plugins development",
"files": [
"dist"

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-bookshelf",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Bookshelf hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -22,8 +22,8 @@
"lodash": "^4.17.11",
"pluralize": "^7.0.0",
"rimraf": "^2.6.3",
"strapi-hook-knex": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-hook-knex": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6"
},
"strapi": {
"dependencies": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-ejs",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "EJS hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-knex",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Knex hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-mongoose",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Mongoose hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -20,7 +20,7 @@
"mongoose-float": "^1.0.4",
"mongoose-long": "^0.2.1",
"pluralize": "^7.0.0",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-utils": "3.0.0-beta.17.6"
},
"author": {
"email": "hi@strapi.io",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-hook-redis",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Redis hook for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [
@ -19,7 +19,7 @@
"lodash": "^4.17.11",
"rimraf": "^2.6.3",
"stack-trace": "0.0.10",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-utils": "3.0.0-beta.17.6"
},
"author": {
"email": "hi@strapi.io",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-middleware-views",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Views middleware to enable server-side rendering for the Strapi framework",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-content-manager",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "A powerful UI to easily manage your data.",
"strapi": {
"name": "Content Manager",
@ -32,8 +32,8 @@
"redux-immutable": "^4.0.0",
"reselect": "^3.0.1",
"showdown": "^1.9.0",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6",
"styled-components": "^4.2.0",
"yup": "^0.27.0"
},

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-content-type-builder",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Strapi plugin to create content type (API).",
"strapi": {
"name": "Content Type Builder",
@ -29,9 +29,9 @@
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"reselect": "^3.0.1",
"strapi-generate": "3.0.0-beta.17.5",
"strapi-generate-api": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-generate": "3.0.0-beta.17.6",
"strapi-generate-api": "3.0.0-beta.17.6",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"yup": "^0.27.0"
},
"author": {

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-documentation",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Documentation",
@ -32,7 +32,7 @@
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"reselect": "^4.0.0",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"swagger-ui-dist": "3.22.1"
},
"author": {

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-email",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Email",
@ -12,13 +12,13 @@
"test": "echo \"no tests yet\""
},
"dependencies": {
"strapi-provider-email-sendmail": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-provider-email-sendmail": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6"
},
"devDependencies": {
"react-copy-to-clipboard": "5.0.1",
"rimraf": "^2.6.3",
"strapi-helper-plugin": "3.0.0-beta.17.5"
"strapi-helper-plugin": "3.0.0-beta.17.6"
},
"author": {
"name": "Strapi team",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-graphql",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "This is the description of the plugin.",
"strapi": {
"name": "graphql",
@ -23,7 +23,7 @@
"graphql-type-long": "^0.1.1",
"koa-compose": "^4.1.0",
"pluralize": "^7.0.0",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-utils": "3.0.0-beta.17.6"
},
"devDependencies": {
"cross-env": "^5.2.0",

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-upload",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "This is the description of the plugin.",
"strapi": {
"name": "Files Upload",
@ -23,9 +23,9 @@
"react-router-dom": "^5.0.0",
"react-transition-group": "^2.5.0",
"reactstrap": "^5.0.0",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-provider-upload-local": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"strapi-provider-upload-local": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6",
"stream-to-array": "^2.3.0",
"uuid": "^3.2.1"
},

View File

@ -1,6 +1,6 @@
{
"name": "strapi-plugin-users-permissions",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Protect your API with a full-authentication process based on JWT",
"strapi": {
"name": "Roles & Permissions",
@ -31,8 +31,8 @@
"reactstrap": "^5.0.0",
"redux-saga": "^0.16.0",
"request": "^2.83.0",
"strapi-helper-plugin": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5",
"strapi-helper-plugin": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6",
"uuid": "^3.1.0"
},
"devDependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-amazon-ses",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Amazon SES provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-mailgun",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Mailgun provider for strapi email plugin",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-sendgrid",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Sendgrid provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-sendmail",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Sendmail provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-aws-s3",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "AWS S3 provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-cloudinary",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Cloudinary provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-local",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Local provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi-provider-upload-rackspace",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Rackspace provider for strapi upload",
"main": "./lib",
"keywords": [],

View File

@ -1,6 +1,6 @@
{
"name": "strapi-utils",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "Shared utilities for the Strapi packages",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "strapi",
"version": "3.0.0-beta.17.5",
"version": "3.0.0-beta.17.6",
"description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MongoDB, MySQL, MariaDB, PostgreSQL, SQLite",
"homepage": "http://strapi.io",
"directories": {
@ -48,15 +48,15 @@
"resolve-cwd": "^3.0.0",
"rimraf": "^2.6.2",
"shelljs": "^0.8.3",
"strapi-generate": "3.0.0-beta.17.5",
"strapi-generate-api": "3.0.0-beta.17.5",
"strapi-generate-controller": "3.0.0-beta.17.5",
"strapi-generate-model": "3.0.0-beta.17.5",
"strapi-generate-new": "3.0.0-beta.17.5",
"strapi-generate-plugin": "3.0.0-beta.17.5",
"strapi-generate-policy": "3.0.0-beta.17.5",
"strapi-generate-service": "3.0.0-beta.17.5",
"strapi-utils": "3.0.0-beta.17.5"
"strapi-generate": "3.0.0-beta.17.6",
"strapi-generate-api": "3.0.0-beta.17.6",
"strapi-generate-controller": "3.0.0-beta.17.6",
"strapi-generate-model": "3.0.0-beta.17.6",
"strapi-generate-new": "3.0.0-beta.17.6",
"strapi-generate-plugin": "3.0.0-beta.17.6",
"strapi-generate-policy": "3.0.0-beta.17.6",
"strapi-generate-service": "3.0.0-beta.17.6",
"strapi-utils": "3.0.0-beta.17.6"
},
"scripts": {
"test": "jest --verbose",