mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Merge pull request #15748 from strapi/chore/docs-api-ref
docs: api reference
This commit is contained in:
commit
3fa939d16a
9
docs/.eslintrc.docs.js
Normal file
9
docs/.eslintrc.docs.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
plugins: ['react'],
|
||||||
|
rules: {
|
||||||
|
'react/prop-types': 0,
|
||||||
|
},
|
||||||
|
};
|
598
docs/docs/api/Strapi.mdx
Normal file
598
docs/docs/api/Strapi.mdx
Normal file
@ -0,0 +1,598 @@
|
|||||||
|
---
|
||||||
|
title: Strapi (WIP)
|
||||||
|
slug: /api/Strapi
|
||||||
|
tags:
|
||||||
|
- class
|
||||||
|
- public
|
||||||
|
- global
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Strapi
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The Strapi class is the main object used in Strapi projects.
|
||||||
|
An instance of Strapi class is available as a global in any Strapi project: `global.strapi`.
|
||||||
|
|
||||||
|
## Class: Strapi
|
||||||
|
|
||||||
|
### `new Strapi(opts)`
|
||||||
|
|
||||||
|
- `opts`: <Type>Object</Type> Options that can be used on Strapi startup
|
||||||
|
- `autoReload`: <Type>Boolean</Type> **Default:** true
|
||||||
|
- If false, deactivate auto reload
|
||||||
|
- If you modify any file in your Strapi project, it reloads your nodejs app
|
||||||
|
- If any content-type is changed, it will reload the nodejs app
|
||||||
|
- `serveAdminPanel`: <Type>Boolean</Type> **Default:** true
|
||||||
|
- Should the admin panel be loaded and serve as a web client
|
||||||
|
- The admin panel build will not be delivered if false
|
||||||
|
- `appDir`: <Type>String</Type> **Default:** `process.cwd()`
|
||||||
|
- The directory relative or absolute path where Strapi will write every file (schemas, generated APIs, controllers or services)
|
||||||
|
- `distDir`: <Type>String</Type> **Default:** appDir value
|
||||||
|
- The directory relative or absolute path where Strapi will read configurations, schemas and any compiled code
|
||||||
|
|
||||||
|
Instances of the Strapi class can be created using the new keyword.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const strapiInstance = new Strapi();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `strapi.container`
|
||||||
|
- [<Type>Container</Type>](./container)
|
||||||
|
|
||||||
|
The container provides a simple and efficient way to register and manage resources, making it easy to access and use them throughout the application.
|
||||||
|
By registering a registry with the container, it can be easily retrieved by other parts of the application, making it a powerful tool for organizing and reusing code across the entire codebase.
|
||||||
|
|
||||||
|
See [Container](./container).
|
||||||
|
|
||||||
|
### `strapi.dirs`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
Stored paths of file system.
|
||||||
|
|
||||||
|
- `dirs.dist`: <Type>[StrapiPathObject](#strapipathobject)</Type>
|
||||||
|
- Build folder
|
||||||
|
- `dirs.app`: <Type>[StrapiPathObject](#strapipathobject)</Type>
|
||||||
|
- Sources folder
|
||||||
|
- `dirs.static`: <Type>Object</Type> Define path to directories involving web client display
|
||||||
|
- `public`: <Type>String</Type> Path to the folder to serve publicly (like files, images, etc..)
|
||||||
|
|
||||||
|
#### StrapiPathObject
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
A set of paths to specific Strapi project parts.
|
||||||
|
|
||||||
|
- `root`: <Type>String</Type> Root path
|
||||||
|
- `src`: <Type>String</Type> Sources route path to project files
|
||||||
|
- `api`: <Type>String</Type> Path to the folder containing project developers' API files (content-types, controllers, services, routes, etc..)
|
||||||
|
- `components`: <Type>String</Type> Path to the folder containing project developers' components
|
||||||
|
- `policies`: <Type>String</Type> Path to the folder where the Strapi project developers' policies are stored
|
||||||
|
- A set of functions that check the state of the data and prevent the access to the API accordingly
|
||||||
|
- `middlewares`: <Type>String</Type> Path to the folder where the Strapi project developers' middlewares are stored
|
||||||
|
- A set of function that wrap around routes and requests
|
||||||
|
- `config`: <Type>String</Type> Path to the folder containing project developers' config files
|
||||||
|
|
||||||
|
### `strapi.isLoaded`
|
||||||
|
- <Type>Boolean</Type>
|
||||||
|
|
||||||
|
- `true`: Everything (all `register` and `bootstrap` functions available in your strapi project) has been loaded
|
||||||
|
- `false`: There is something loading
|
||||||
|
|
||||||
|
Note: `register` functions are called before the `bootstrap` functions.
|
||||||
|
|
||||||
|
### `strapi.reload()`
|
||||||
|
|
||||||
|
Reload the app.
|
||||||
|
|
||||||
|
This function defines itself at the construction of the Strapi class.
|
||||||
|
|
||||||
|
### `strapi.server`
|
||||||
|
- [<Type>StrapiServer</Type>](./strapi-server)
|
||||||
|
|
||||||
|
Strapi server object.
|
||||||
|
|
||||||
|
### `strapi.fs`
|
||||||
|
- [<Type>StrapiFS</Type>](StrapiFS)
|
||||||
|
|
||||||
|
Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.html).
|
||||||
|
|
||||||
|
### `strapi.eventHub`
|
||||||
|
- [<Type>EventHub</Type>](EventHub)
|
||||||
|
|
||||||
|
The `strapi.eventHub` object is used to manipulate events within a Strapi project. It is an instance of the built-in EventEmitter class from Node.js, which provides a simple way to emit and listen for events.
|
||||||
|
|
||||||
|
The `strapi.eventHub` object is created using the `createEventHub()` function in the [EventHub](EventHub) module of the Strapi core. This function returns a new instance of the EventHub class, which extends the EventEmitter class and adds some additional functionality specific to Strapi.
|
||||||
|
|
||||||
|
|
||||||
|
#### Examples:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Listen for a 'user.updated' event and log the data
|
||||||
|
strapi.eventHub.on('user.updated', (data) => {
|
||||||
|
console.log(`User ${data.id} has been updated`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Emit a 'user.created' event with some data
|
||||||
|
strapi.eventHub.emit('user.created', { username: 'johndoe', email: 'johndoe@example.com' });
|
||||||
|
```
|
||||||
|
In this example, we are emitting a `user.created` event with some data attached to it, and then listening for a user.updated event and logging the data. These events can be used to trigger actions within the Strapi application or to communicate with external systems.
|
||||||
|
|
||||||
|
For more information on how to use the EventEmitter class and its methods, see the [Node.js documentation](ttps://nodejs.org/docs/latest-v18.x/api/events.html#class-eventemitter).
|
||||||
|
|
||||||
|
### `strapi.startupLogger`
|
||||||
|
- [<Type>StartupLogger</Type>](StartupLogger)
|
||||||
|
|
||||||
|
Object containing predefined logger functions. Used for Strapi startup. (do not use as a logger elsewhere)
|
||||||
|
|
||||||
|
### `strapi.log`
|
||||||
|
- [<Type>Winston</Type>](https://github.com/winstonjs/winston#creating-your-own-logger)
|
||||||
|
|
||||||
|
A logger provided by Strapi that uses the Winston logging library. It is the result of calling the `winston.createLogger()` function with the configuration defined by the user of the Strapi application.
|
||||||
|
|
||||||
|
The logger provides various methods for logging messages at different levels of severity, including error, warn, info, verbose, debug, and silly. The logging level can be set via the configuration to control which messages are logged.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
```javascript
|
||||||
|
// Log an error message
|
||||||
|
strapi.log.error('Failed to start server', { error: err });
|
||||||
|
|
||||||
|
// Log a warning message
|
||||||
|
strapi.log.warn('Server is running in development mode');
|
||||||
|
|
||||||
|
// Log an informational message
|
||||||
|
strapi.log.info(`Server started on port ${PORT}`);
|
||||||
|
|
||||||
|
// Log a verbose message
|
||||||
|
strapi.log.verbose('Application state', { user: currentUser });
|
||||||
|
|
||||||
|
// Log a debug message
|
||||||
|
strapi.log.debug('API request received', { method: req.method, path: req.path });
|
||||||
|
|
||||||
|
// Log a silly message
|
||||||
|
strapi.log.silly('Entered loop', { count: i });
|
||||||
|
```
|
||||||
|
In these examples, we are logging messages at different levels of severity, including error, warn, info, verbose, debug, and silly. We are also passing in metadata as an object in the second parameter of each logging method.
|
||||||
|
|
||||||
|
The messages logged by strapi.log will be output according to the logging configuration set by the user of the Strapi application. This configuration determines which messages are logged and where they are logged (e.g. console, file, etc.).
|
||||||
|
|
||||||
|
### `strapi.cron`
|
||||||
|
- [<Type>CronService</Type>](Cron)
|
||||||
|
|
||||||
|
Module to schedule cron jobs for Strapi project. It is an instance of a custom Cron object.
|
||||||
|
|
||||||
|
### `strapi.telemetry`
|
||||||
|
- [<Type>TelemetryService</Type>](Telemetry)
|
||||||
|
|
||||||
|
The `strapi.telemetry` property provides access to the telemetry service instance. This service collects anonymous usage data about your Strapi application to help the Strapi team improve the product.
|
||||||
|
|
||||||
|
By default, the telemetry service is enabled, but you can disable it by setting the telemetryDisabled property to true in your application's package.json file, or by setting the `STRAPI_TELEMETRY_DISABLED` environment variable to true. You can also disable telemetry programmatically by setting the isDisabled property of the `strapi.telemetry` instance to true.
|
||||||
|
|
||||||
|
### `strapi.requestContext`
|
||||||
|
- <Type>Object</Type> Context Storage
|
||||||
|
|
||||||
|
- `run(store, cb)`: <Type>Function</Type>
|
||||||
|
- `store`: <Type>Any</Type> Value that should be retrieved
|
||||||
|
- `cb`: <Type>Function</Type> Callback
|
||||||
|
- `get()` <Type>Function</Type>
|
||||||
|
|
||||||
|
The request context stores the ctx object from KoaJS on each request. This allows users to have access to the context from anywhere through the Strapi instance.
|
||||||
|
|
||||||
|
### `strapi.customFields`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
- `register(customField)`: <Type>Function</Type> Register a new custom field
|
||||||
|
|
||||||
|
This property is a shortcut to `strapi.container.get('custom-fields').add(customField)`.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
```javascript
|
||||||
|
strapi.customFields.register({
|
||||||
|
name: 'color',
|
||||||
|
plugin: 'color-picker',
|
||||||
|
type: 'string',
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### `strapi.config`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('config')`.
|
||||||
|
|
||||||
|
See the [config container](#config).
|
||||||
|
|
||||||
|
### `strapi.services`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('services').getAll()`.
|
||||||
|
|
||||||
|
See the [services' container](#services).
|
||||||
|
|
||||||
|
### `strapi.service(uid)`
|
||||||
|
- `uid`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('services').get(uid)`.
|
||||||
|
|
||||||
|
See the [services' container](#services).
|
||||||
|
|
||||||
|
### `strapi.controllers`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('controllers').getAll()`.
|
||||||
|
|
||||||
|
See the [controllers' container](#controllers).
|
||||||
|
|
||||||
|
### `strapi.controller(uid)`
|
||||||
|
- `uid`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('controllers').get(uid)`.
|
||||||
|
|
||||||
|
See the [controllers' container](#controllers).
|
||||||
|
|
||||||
|
### `strapi.contentTypes`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('content-types').getAll()`.
|
||||||
|
|
||||||
|
See the [content-types' container](#content-types).
|
||||||
|
|
||||||
|
### `strapi.contentType(name)`
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('content-types').get(name)`.
|
||||||
|
|
||||||
|
See the [content-types' container](#content-types).
|
||||||
|
|
||||||
|
### `strapi.policies`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('policies').getAll()`.
|
||||||
|
|
||||||
|
See the [policies' container](#policies).
|
||||||
|
|
||||||
|
### `strapi.policy(name)`
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('policies').get(name)`.
|
||||||
|
|
||||||
|
See the [policies' container](#policies).
|
||||||
|
|
||||||
|
### `strapi.middlewares`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('middlewares').getAll()`.
|
||||||
|
|
||||||
|
See the [middlewares container](#middlewares).
|
||||||
|
|
||||||
|
### `strapi.middleware(name)`
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('middlewares').get(name)`.
|
||||||
|
|
||||||
|
See the [middlewares container](#middlewares).
|
||||||
|
|
||||||
|
### `strapi.plugins`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('plugins').getAll()`.
|
||||||
|
|
||||||
|
See the [plugins' container](#plugins).
|
||||||
|
|
||||||
|
### `strapi.plugin(name)`
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('plugins').get(name)`.
|
||||||
|
|
||||||
|
See the [plugins' container](#plugins).
|
||||||
|
|
||||||
|
### `strapi.hooks`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('hooks').getAll()`.
|
||||||
|
|
||||||
|
See the [hooks' container](#hooks).
|
||||||
|
|
||||||
|
### `strapi.hook(name)`
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('hooks').get(name)`.
|
||||||
|
|
||||||
|
See the [hooks' container](#hooks).
|
||||||
|
|
||||||
|
### `strapi.api`
|
||||||
|
- <Type>Object[]</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('apis').getAll()`.
|
||||||
|
|
||||||
|
See the [apis container](#apis).
|
||||||
|
|
||||||
|
### `strapi.auth`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('auth')`.
|
||||||
|
|
||||||
|
See the [auth' container](#auth).
|
||||||
|
|
||||||
|
### `strapi.contentAPI`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('content-api')`.
|
||||||
|
|
||||||
|
See the [content-api container](#content-api).
|
||||||
|
|
||||||
|
### `strapi.sanitizers`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
Shortcut to `strapi.container.get('sanitizers')`.
|
||||||
|
|
||||||
|
See the [sanitizers' container](#sanitizers).
|
||||||
|
|
||||||
|
### `strapi.start()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.destroy()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.sendStartupTelemetry()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.openAdmin({ isInitialized })`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.postListen()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.listen()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.stopWithError()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.stop(exitCode)`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadAdmin()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadPlugins()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadPolicies()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadAPIs()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadComponents()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadMiddlewares()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadApp()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.loadSanitizers()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.registerInternalHooks()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.register()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.bootstrap()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.load()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.startWebhooks()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.reload()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.runLifecyclesFunctions()`
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.getModel(uid)`
|
||||||
|
- `uid`: <Type>String</Type>
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapi.query(uid)`
|
||||||
|
- `uid`: <Type>String</Type>
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
## Strapi containers
|
||||||
|
|
||||||
|
The strapi containers are accessible via `strapi.container.get('name-of-the-container')`.
|
||||||
|
|
||||||
|
### `config`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
- `get(path, defaultValue)`: <Type>Function</Type>
|
||||||
|
- `path`: <Type>String</Type>
|
||||||
|
- `defaultValue`: <Type>Any</Type>
|
||||||
|
- Returns: <Type>Any</Type> - The value located at `path` or, if undefined, `defaultValue`.
|
||||||
|
- `set(path, value)`: <Type>Function</Type>
|
||||||
|
- `path`: <Type>String</Type> - Where the value should be stored
|
||||||
|
- `value`: <Type>Any</Type>
|
||||||
|
- `has(path)`: <Type>Function</Type>
|
||||||
|
- `path`: <Type>String</Type>
|
||||||
|
- Returns: <Type>Boolean</Type> - Does the `path` match a value stored in the config container.
|
||||||
|
- `launchedAt`: <Type>Number</Type> **Default:** `Date.now()`
|
||||||
|
Date in milliseconds when the server has started
|
||||||
|
- `serveAdminPanel`: <Type>Boolean</Type> **Default:** `true`
|
||||||
|
See [Strapi constructor](#new-strapiopts) options
|
||||||
|
- `autoReload`: <Type>Boolean</Type> **Default:** `false`
|
||||||
|
See [Strapi constructor](#new-strapiopts) options
|
||||||
|
- `environment`: <Type>String</Type> - process.env.NODE_ENV
|
||||||
|
- `uuid`: <Type>String</Type> - string extracted from `package.json` located in `strapi.uuid`
|
||||||
|
- `packageJsonStrapi`: <Type>Object</Type> - object extracted from `package.json` located in `strapi` (except uuid)
|
||||||
|
- `info`: <Type>Object</Type>
|
||||||
|
- everything stored in the `package.json`
|
||||||
|
- `strapi`: <Type>String</Type> - Current version of Strapi
|
||||||
|
|
||||||
|
Every file stored under the `config` folder will be injected in this config container object.
|
||||||
|
|
||||||
|
### `services`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `controllers`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `content-types`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `policies`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `plugins`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `hooks`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `apis`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `auth`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `content-api`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `sanitizers`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
29
docs/docs/api/api.mdx
Normal file
29
docs/docs/api/api.mdx
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
title: API (WIP)
|
||||||
|
slug: /api/API
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# API
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The Strapi API module permits to generate a Strapi API object that wrap all the functionalities around Strapi endpoints
|
||||||
|
|
||||||
|
## Module: API
|
||||||
|
|
||||||
|
### `createAPI(strapi, opts)`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
13
docs/docs/api/components/type.jsx
Normal file
13
docs/docs/api/components/type.jsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export default function Type({ children }) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: '#017501',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<{children}>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
102
docs/docs/api/container.mdx
Normal file
102
docs/docs/api/container.mdx
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
---
|
||||||
|
title: Container
|
||||||
|
slug: /api/container
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 5
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Container
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The container module permits to generate containers.
|
||||||
|
|
||||||
|
## Module: container
|
||||||
|
|
||||||
|
### `createContainer(strapi)`
|
||||||
|
|
||||||
|
- `strapi`: <Type>Strapi</Type> [See Strapi class documentation](Strapi.mdx)
|
||||||
|
- Returns: <Type>Container</Type>
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const container = createContainer(strapi);
|
||||||
|
|
||||||
|
container.register('config', {
|
||||||
|
get: (configName) => {},
|
||||||
|
set: (configName, value) => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const dbConfig = container.get('config').get('database');
|
||||||
|
```
|
||||||
|
|
||||||
|
### `container.register(name, resolver)`
|
||||||
|
|
||||||
|
- `name`: <Type>String</Type> UID of the content
|
||||||
|
- `resolver`: <Type>Function</Type> | <Type>Any</Type>
|
||||||
|
- As a function, the function will be executed when the first get method is called on this content. The result of this function will define the content of this UID.
|
||||||
|
- `resolver(context, args)`
|
||||||
|
- `context`: <Type>{ Strapi }</Type> [See Strapi class documentation](Strapi.mdx)
|
||||||
|
- `args`: <Type>Any</Type> Anything to be used by the resolver function
|
||||||
|
- As anything else, this value will be resolved when getting this specified content through its UID.
|
||||||
|
|
||||||
|
Register a new content to be accessed inside the container. If the name is already used, it will throw an error.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const container = createContainer(strapi);
|
||||||
|
|
||||||
|
container.register('config', ({ strapi }, args) => {});
|
||||||
|
// or
|
||||||
|
container.register('services', {});
|
||||||
|
```
|
||||||
|
|
||||||
|
### `container.get(name, args)`
|
||||||
|
|
||||||
|
- `name`: <Type>String</Type> UID of the content
|
||||||
|
- `args`: <Type>Any</Type> Value that will be passed to the resolver (if function)
|
||||||
|
|
||||||
|
Get the value stored for a specific `name`.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const container = createContainer(strapi);
|
||||||
|
|
||||||
|
container.register('config', { db: 'sqlite' });
|
||||||
|
|
||||||
|
const config = container.get('config');
|
||||||
|
// config.db === 'sqlite'
|
||||||
|
```
|
||||||
|
|
||||||
|
⚠️ If the **resolver**, used in the [register function](#containerregistername-resolver), is a **function**, the value will be the result of this resolver function with `args` as parameter on the first call to `get`.
|
||||||
|
|
||||||
|
Please pay attention that the resolver result value isn't awaited. So if resolver returns a promise, the value stored will be a promise.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const container = createContainer(strapi);
|
||||||
|
|
||||||
|
container.register('boolean', (bool) => bool);
|
||||||
|
|
||||||
|
// First call - The value is resolved through the resolver above "(bool) => bool"
|
||||||
|
container.get('boolean', true);
|
||||||
|
// true
|
||||||
|
|
||||||
|
// Any further call will use the previously set value
|
||||||
|
container.get('boolean');
|
||||||
|
// true
|
||||||
|
|
||||||
|
// Even if we try to push a new value
|
||||||
|
container.get('boolean', false);
|
||||||
|
// true
|
||||||
|
```
|
||||||
|
### `container.extend()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
To be developed
|
||||||
|
:::
|
195
docs/docs/api/cron.mdx
Normal file
195
docs/docs/api/cron.mdx
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
---
|
||||||
|
title: Cron Service
|
||||||
|
slug: /api/Cron
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Cron
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The Strapi Cron Service provides a way to add, remove, start, and stop cron jobs in a Strapi application.
|
||||||
|
|
||||||
|
|
||||||
|
## Module: Cron Service
|
||||||
|
|
||||||
|
### createCronService()
|
||||||
|
|
||||||
|
The `createCronService()` function returns an object that provides methods to manage cron jobs.
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### `cron.add(tasks)`
|
||||||
|
|
||||||
|
- `tasks`: <Type>Object</Type>
|
||||||
|
- Returns: `this`
|
||||||
|
|
||||||
|
Adds one or more cron tasks to the service.
|
||||||
|
|
||||||
|
- Each key of the `tasks` object is the name of the task.
|
||||||
|
- Each value of the `tasks` object can be either a function, or an object with two properties: `task` and `options`.
|
||||||
|
- If the value is a function, it is used as the task to be executed when the cron expression is met.
|
||||||
|
- The key will be considered as the cron expression
|
||||||
|
- If the value is an object, its `task` property is used as the task function, and its `options` property is used as the cron expression options.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
const { createCronService } = require('packages/core/strapi/lib/services/cron.js');
|
||||||
|
|
||||||
|
const cron = createCronService();
|
||||||
|
|
||||||
|
const task = () => {
|
||||||
|
console.log('Task executed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
cron.add({
|
||||||
|
myTask: {
|
||||||
|
task,
|
||||||
|
options: '*/5 * * * *', // Executes every 5 minutes.
|
||||||
|
},
|
||||||
|
'*/1 * * * *': () => console.log('A minute has passed.'),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### `cron.remove(name)`
|
||||||
|
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
- Returns: `this`
|
||||||
|
|
||||||
|
Removes a cron task from the service.
|
||||||
|
|
||||||
|
- The `name` parameter is the name of the task to remove.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
const { createCronService } = require('packages/core/strapi/lib/services/cron.js');
|
||||||
|
|
||||||
|
const cron = createCronService();
|
||||||
|
|
||||||
|
const task = () => {
|
||||||
|
console.log('Task executed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
cron.add({
|
||||||
|
myTask: {
|
||||||
|
task,
|
||||||
|
options: '*/5 * * * *', // Executes every 5 minutes.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
cron.remove('myTask');
|
||||||
|
```
|
||||||
|
|
||||||
|
### `cron.start()`
|
||||||
|
|
||||||
|
- Returns: `this`
|
||||||
|
|
||||||
|
Starts the cron service.
|
||||||
|
|
||||||
|
- Schedules all the cron jobs.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
const { createCronService } = require('packages/core/strapi/lib/services/cron.js');
|
||||||
|
|
||||||
|
const cron = createCronService();
|
||||||
|
|
||||||
|
const task = () => {
|
||||||
|
console.log('Task executed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
cron.add({
|
||||||
|
myTask: {
|
||||||
|
task,
|
||||||
|
options: '*/5 * * * *', // Executes every 5 minutes.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
cron.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `cron.stop()`
|
||||||
|
|
||||||
|
- Returns: `this`
|
||||||
|
|
||||||
|
Stops the cron service.
|
||||||
|
|
||||||
|
- Cancels all the scheduled jobs.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
const { createCronService } = require('packages/core/strapi/lib/services/cron.js');
|
||||||
|
|
||||||
|
const cron = createCronService();
|
||||||
|
|
||||||
|
const task = () => {
|
||||||
|
console.log('Task executed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
cron.add({
|
||||||
|
myTask: {
|
||||||
|
task,
|
||||||
|
options: '*/5 * * * *', // Executes every 5 minutes.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start the scheduled cron jobs
|
||||||
|
cron.start();
|
||||||
|
// Stops the cron jobs
|
||||||
|
cron.stop();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `cron.destroy()`
|
||||||
|
|
||||||
|
- Returns: `this`
|
||||||
|
|
||||||
|
Destroys the cron service.
|
||||||
|
|
||||||
|
- Calls the `stop()` method.
|
||||||
|
- Clears the list of cron jobs.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
const { createCronService } = require('packages/core/strapi/lib/services/cron.js');
|
||||||
|
|
||||||
|
const cron = createCronService();
|
||||||
|
|
||||||
|
const task = () => {
|
||||||
|
console.log('Task executed!');
|
||||||
|
};
|
||||||
|
|
||||||
|
cron.add({
|
||||||
|
myTask: {
|
||||||
|
task,
|
||||||
|
options: '*/5 * * * *', // Executes every 5 minutes.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start the scheduled cron jobs
|
||||||
|
cron.start();
|
||||||
|
// Stops the cron jobs and remove all scheduled tasks
|
||||||
|
cron.destroy();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### `cron.jobs`
|
||||||
|
- <Type>Array</Type>
|
||||||
|
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
- `job`: [<Type>Job</Type>](https://github.com/node-schedule/node-schedule) - Job object by node-schedule
|
||||||
|
- `options`: <Type>String</Type> - String representing the recurrence of the job ( like '*/5 * * * *' )
|
||||||
|
- `name`: <Type>String</Type> - The name of the task associated to the job
|
||||||
|
|
||||||
|
An array of the cron jobs added to the service.
|
29
docs/docs/api/event-hub.mdx
Normal file
29
docs/docs/api/event-hub.mdx
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
title: EventHub (WIP)
|
||||||
|
slug: /api/EventHub
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Strapi Event Hub
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
Strapi Event Hub module - description to be done
|
||||||
|
|
||||||
|
## Module: EventHub
|
||||||
|
|
||||||
|
### `createEventHub()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
@ -1 +0,0 @@
|
|||||||
# API
|
|
72
docs/docs/api/startup-logger.mdx
Normal file
72
docs/docs/api/startup-logger.mdx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
---
|
||||||
|
title: Startup Logger
|
||||||
|
slug: /api/StartupLogger
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- private
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# API
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
This module is a simple logger for starting up Strapi with some useful information.
|
||||||
|
|
||||||
|
## Module: Startup Logger
|
||||||
|
|
||||||
|
### `logStats()`
|
||||||
|
|
||||||
|
This log will display information about the instance of Strapi. The time launched, how many times it took and important configuration information.
|
||||||
|
|
||||||
|
```
|
||||||
|
Project information
|
||||||
|
|
||||||
|
┌────────────────────┬──────────────────────────────────────────────────┐
|
||||||
|
│ Time │ Wed Jan 01 2000 00:00:01 GMT+0200 (Central Euro… │
|
||||||
|
│ Launched in │ 2000 ms │
|
||||||
|
│ Environment │ development │
|
||||||
|
│ Process PID │ 42 │
|
||||||
|
│ Version │ 4.9.0 (node v18.12.1) │
|
||||||
|
│ Edition │ Enterprise │
|
||||||
|
│ Database │ postgres │
|
||||||
|
└────────────────────┴──────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### `logFirstStartupMessage()`
|
||||||
|
|
||||||
|
This log will display the first time Strapi project is launched. It will ask the user to create its first admin user in the admin panel.
|
||||||
|
|
||||||
|
### `logDefaultStartupMessage()`
|
||||||
|
|
||||||
|
Default message to display when the Strapi server is started.
|
||||||
|
|
||||||
|
```
|
||||||
|
Actions available
|
||||||
|
|
||||||
|
Welcome back!
|
||||||
|
To manage your project 🚀, go to the administration panel at:
|
||||||
|
http://localhost:1337/admin
|
||||||
|
|
||||||
|
To access the server ⚡️, go to:
|
||||||
|
http://localhost:1337
|
||||||
|
```
|
||||||
|
|
||||||
|
### `logStartupMessage({ isInitialized })`
|
||||||
|
|
||||||
|
- `isInitialized`: <Type>Boolean</Type> Has the Strapi project already been initialized?
|
||||||
|
|
||||||
|
Will display the correct start-up message according to the specified boolean.
|
||||||
|
|
||||||
|
:::note
|
||||||
|
|
||||||
|
Can be disabled by setting `STRAPI_HIDE_STARTUP_MESSAGE` to `true`.
|
||||||
|
|
||||||
|
:::
|
42
docs/docs/api/strapi-fs.mdx
Normal file
42
docs/docs/api/strapi-fs.mdx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
title: StrapiFS (WIP)
|
||||||
|
slug: /api/StrapiFS
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Strapi File System
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The Strapi FS module is a wrapper around FS NodeJS module to manipulate local files.
|
||||||
|
|
||||||
|
## Module: StrapiFS
|
||||||
|
|
||||||
|
### `createStrapiFs(strapi)`
|
||||||
|
|
||||||
|
### `strapiFs.writeAppFile(optPath, data)`
|
||||||
|
:::caution
|
||||||
|
Deprecated
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapiFs.writePluginFile(plugin, optPath, data)`
|
||||||
|
:::caution
|
||||||
|
Deprecated
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapiFs.removeAppFile(optPath)`
|
||||||
|
:::caution
|
||||||
|
Deprecated
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `strapiFs.appendFile(optPath, data)`
|
117
docs/docs/api/strapi-server.mdx
Normal file
117
docs/docs/api/strapi-server.mdx
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
---
|
||||||
|
title: Strapi server (WIP)
|
||||||
|
slug: /api/strapi-server
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 5
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Strapi Server
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The Strapi server module permits to generate a Strapi http server.
|
||||||
|
|
||||||
|
## Module: Strapi server
|
||||||
|
|
||||||
|
### `createServer(strapi)`
|
||||||
|
|
||||||
|
- `strapi`: [<Type>Strapi</Type>](Strapi)
|
||||||
|
- Returns: <Type>StrapiServer</Type>
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const server = createServer(strapi);
|
||||||
|
|
||||||
|
server.listRoutes();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `StrapiServer.app`
|
||||||
|
|
||||||
|
- [<Type>KoaJS</Type>](https://devdocs.io/koa/index)
|
||||||
|
|
||||||
|
Strapi projects are using KoaJS to run the NodeJS server.
|
||||||
|
|
||||||
|
### `StrapiServer.router`
|
||||||
|
|
||||||
|
- [<Type>@koa/router</Type>](https://github.com/ZijianHe/koa-router#router-)
|
||||||
|
|
||||||
|
Strapi projects are using a dependency of KoaJS called @koa/router.
|
||||||
|
|
||||||
|
### `StrapiServer.httpServer`
|
||||||
|
|
||||||
|
- [<Type>http.Server</Type>](https://nodejs.org/docs/latest-v18.x/api/http.html)
|
||||||
|
|
||||||
|
The Strapi's HTTP server.
|
||||||
|
|
||||||
|
### `StrapiServer.api(name)`
|
||||||
|
|
||||||
|
- `name`: <Type>String</Type>
|
||||||
|
- Returns: [<Type>StrapiAPIs</Type>](#strapiapis)
|
||||||
|
|
||||||
|
Getter for apis available in Strapi
|
||||||
|
|
||||||
|
### `StrapiServer.use(...args)`
|
||||||
|
|
||||||
|
- [<Type>KoaApp.use</Type>](https://devdocs.io/koa/index#appusefunction)
|
||||||
|
|
||||||
|
Shortcut for Koa `app.use(...args)` method.
|
||||||
|
|
||||||
|
### `StrapiServer.routes(routes)`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.mount()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.initRouting()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.initMiddlewares()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.listRoutes()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.listen(...args)`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiServer.destroy()`
|
||||||
|
|
||||||
|
:::info
|
||||||
|
TODO
|
||||||
|
:::
|
||||||
|
|
||||||
|
### `StrapiAPIs`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
- `content-api`: [<Type>API</Type>](API)
|
||||||
|
- API used by external requesters
|
||||||
|
- `admin`: [<Type>API</Type>](API)
|
||||||
|
- API used by admin panel
|
||||||
|
|
||||||
|
Strapi APIs is a map of all APIs available inside the Strapi project.
|
93
docs/docs/api/structure.example
Normal file
93
docs/docs/api/structure.example
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
---
|
||||||
|
title: API Reference example
|
||||||
|
tags:
|
||||||
|
- utils
|
||||||
|
- class
|
||||||
|
- public
|
||||||
|
- global
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Name of Module
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable** | **Legacy** | **Deprecated**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
_**Stable** - can be use as is_
|
||||||
|
|
||||||
|
_**Legacy** - Old code that needs refactoring to match the current architecture of the code_
|
||||||
|
|
||||||
|
_**Deprecated** - Should **NOT** be used, this will be deleted anytime soon_
|
||||||
|
|
||||||
|
_Description with a general example on how to use this Class / Module_
|
||||||
|
|
||||||
|
## Class: Name of the class
|
||||||
|
|
||||||
|
### Public variable (e.g. in an EventEmitter class `Event: 'close'`)
|
||||||
|
|
||||||
|
### Static methods (e.g. `Static method: Class.default()`)
|
||||||
|
|
||||||
|
### `new Class()`
|
||||||
|
|
||||||
|
Instances of the Class class can be created using the new keyword.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const myClass = new Class();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `class.method(param1, param2)`
|
||||||
|
|
||||||
|
- `param1`: <Type>String</Type> (can be linked to other API doc page).
|
||||||
|
- `param2`: <Type>Object</Type>
|
||||||
|
- `options1`: <Type>Number</Type>
|
||||||
|
|
||||||
|
The `class.method()` method display the `param1` and then skip `param2` lines.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { Class } = require('pathToClassFile');
|
||||||
|
const textLines = ['Welcome', "That's all", 'Thanks'];
|
||||||
|
|
||||||
|
const classInstance = new Class();
|
||||||
|
|
||||||
|
for (const text of textLines) {
|
||||||
|
classInstance.method(text, 1);
|
||||||
|
}
|
||||||
|
// Prints:
|
||||||
|
// Welcome
|
||||||
|
// That's all
|
||||||
|
// Thanks
|
||||||
|
```
|
||||||
|
|
||||||
|
## Function: `name_of_the_function(param1, param2)`
|
||||||
|
|
||||||
|
- `param1`: <Type>String</Type> (can be linked to other API doc page)
|
||||||
|
- `param2`: <Type>Object</Type>
|
||||||
|
- `options1`: <Type>Number</Type>
|
||||||
|
|
||||||
|
The `name_of_the_function()` method display the `param1` and then skip `param2` lines.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { name_of_the_function } = require('pathToFunctionFile');
|
||||||
|
const textLines = ['Welcome', "That's all", 'Thanks'];
|
||||||
|
|
||||||
|
for (const text of textLines) {
|
||||||
|
name_of_the_function(text, 1);
|
||||||
|
}
|
||||||
|
// Prints:
|
||||||
|
// Welcome
|
||||||
|
// That's all
|
||||||
|
// Thanks
|
||||||
|
```
|
||||||
|
|
||||||
|
This structure is highly based on NodeJS API reference documentation. https://nodejs.org/api
|
102
docs/docs/api/telemetry.mdx
Normal file
102
docs/docs/api/telemetry.mdx
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
---
|
||||||
|
title: Telemetry Service
|
||||||
|
slug: /api/Telemetry
|
||||||
|
tags:
|
||||||
|
- module
|
||||||
|
- public
|
||||||
|
|
||||||
|
toc_min_heading_level: 2
|
||||||
|
toc_max_heading_level: 3
|
||||||
|
---
|
||||||
|
import Type from '@site/docs/api/components/type';
|
||||||
|
|
||||||
|
# Telemetry
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
Current state: **Stable**
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
The telemetry service is responsible for collecting and sending anonymous usage data to Strapi. This service is disabled by default, but can be enabled or disabled via configuration.
|
||||||
|
|
||||||
|
## Usage Information
|
||||||
|
The collected usage data is used to help Strapi improve the product by identifying areas of improvement, tracking feature adoption, and measuring performance. You can learn more about the usage data that is collected by visiting the following link:
|
||||||
|
|
||||||
|
https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html
|
||||||
|
|
||||||
|
## Module: Telemetry Service
|
||||||
|
|
||||||
|
### createTelemetryInstance()
|
||||||
|
|
||||||
|
- strapi: [<Type>Strapi</Type>](Strapi) - A strapi instance.
|
||||||
|
|
||||||
|
The `createTelemetryInstance()` function returns an instance of the Telemetry service.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const createTelemetryInstance = require('path/to/telemetry');
|
||||||
|
|
||||||
|
const telemetry = createTelemetryInstance(strapi);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### `telemetry.register()`
|
||||||
|
|
||||||
|
Registers the telemetry instance.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
telemetry.register();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `telemetry.bootstrap()`
|
||||||
|
|
||||||
|
Bootstraps the telemetry instance.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
telemetry.bootstrap();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `telemetry.destroy()`
|
||||||
|
|
||||||
|
Destroys the telemetry instance.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
telemetry.destroy();
|
||||||
|
```
|
||||||
|
|
||||||
|
### `telemetry.send(event, payload)`
|
||||||
|
- `event`: <Type>String</Type> - The event to be sent.
|
||||||
|
- `payload`: [<Type>TelemetryPayload</Type>](#telemetrypayload) - The payload to be sent with the event.
|
||||||
|
- Returns: Promise
|
||||||
|
|
||||||
|
Sends telemetry event with the given payload.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
telemetry.send('event_name', { key: 'value' });
|
||||||
|
```
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
### `TelemetryPayload`
|
||||||
|
- <Type>Object</Type>
|
||||||
|
|
||||||
|
- `eventProperties`: <Type>Object</Type> An object that contains additional information about the event.
|
||||||
|
- `userProperties`: <Type>Object</Type> An object that defines the identity of the user who triggered the event.
|
||||||
|
- `groupProperties`: <Type>Object</Type> An object that defines properties of the application or environment in which the event occurred.
|
||||||
|
|
||||||
|
Examples of event properties in Strapi include model, containsRelationalFields, displayedFields, kind, and hasDraftAndPublish. These properties are specific to the event and are used to provide additional context about what happened.
|
||||||
|
|
||||||
|
User properties can include information such as the user's operating system, node version, and hostname. These properties are typically used to group events by user or to filter events based on certain user characteristics.
|
||||||
|
|
||||||
|
Group properties can include information such as the language(s) used in the application, the database being used, and the number of locales. These properties are typically used to group events by application version, environment, or other characteristics.
|
@ -110,7 +110,7 @@ class Strapi {
|
|||||||
// Instantiate the Koa app & the HTTP server
|
// Instantiate the Koa app & the HTTP server
|
||||||
this.server = createServer(this);
|
this.server = createServer(this);
|
||||||
|
|
||||||
// Strapi utils instanciation
|
// Strapi utils instantiation
|
||||||
this.fs = createStrapiFs(this);
|
this.fs = createStrapiFs(this);
|
||||||
this.eventHub = createEventHub();
|
this.eventHub = createEventHub();
|
||||||
this.startupLogger = createStartupLogger(this);
|
this.startupLogger = createStartupLogger(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user