mirror of
https://github.com/strapi/strapi.git
synced 2025-09-02 13:23:12 +00:00
81 lines
26 KiB
HTML
81 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>Introduction | Strapi Docs</title>
|
|
<meta name="description" content="API creation made simple, secure and fast.">
|
|
|
|
|
|
<link rel="preload" href="/documentation/assets/css/styles.a8210063.css" as="style"><link rel="preload" href="/documentation/assets/js/app.a8210063.js" as="script"><link rel="preload" href="/documentation/assets/js/14.7cfd4cb8.js" as="script"><link rel="prefetch" href="/documentation/assets/js/28.9b077c15.js"><link rel="prefetch" href="/documentation/assets/css/1.styles.77d89b12.css"><link rel="prefetch" href="/documentation/assets/js/1.77d89b12.js"><link rel="prefetch" href="/documentation/assets/css/2.styles.08038ddb.css"><link rel="prefetch" href="/documentation/assets/js/2.08038ddb.js"><link rel="prefetch" href="/documentation/assets/js/3.4d92d5e3.js"><link rel="prefetch" href="/documentation/assets/js/4.385ae6a0.js"><link rel="prefetch" href="/documentation/assets/js/5.edd21cb3.js"><link rel="prefetch" href="/documentation/assets/js/6.fd6e4b24.js"><link rel="prefetch" href="/documentation/assets/js/7.e1f45fa9.js"><link rel="prefetch" href="/documentation/assets/js/8.dc78e1c2.js"><link rel="prefetch" href="/documentation/assets/js/9.fd6a21e6.js"><link rel="prefetch" href="/documentation/assets/js/10.f9e7d997.js"><link rel="prefetch" href="/documentation/assets/js/11.bfb9de0f.js"><link rel="prefetch" href="/documentation/assets/js/12.124227d1.js"><link rel="prefetch" href="/documentation/assets/js/13.d8092700.js"><link rel="prefetch" href="/documentation/assets/js/15.55a20f7c.js"><link rel="prefetch" href="/documentation/assets/js/16.5c84c402.js"><link rel="prefetch" href="/documentation/assets/js/17.1c93d494.js"><link rel="prefetch" href="/documentation/assets/js/18.e1f1758f.js"><link rel="prefetch" href="/documentation/assets/js/19.8d1b00cd.js"><link rel="prefetch" href="/documentation/assets/js/20.856d7bdd.js"><link rel="prefetch" href="/documentation/assets/js/21.6f851286.js"><link rel="prefetch" href="/documentation/assets/js/22.7ddb4e1d.js"><link rel="prefetch" href="/documentation/assets/js/23.15e5a0c3.js"><link rel="prefetch" href="/documentation/assets/js/24.6fdf34d0.js"><link rel="prefetch" href="/documentation/assets/js/25.21c9a549.js"><link rel="prefetch" href="/documentation/assets/js/26.6608295c.js"><link rel="prefetch" href="/documentation/assets/js/27.2c9596ea.js"><link rel="prefetch" href="/documentation/assets/js/29.8ea8ecc1.js"><link rel="prefetch" href="/documentation/assets/js/30.5d2829b8.js"><link rel="prefetch" href="/documentation/assets/js/31.fad00a3a.js"><link rel="prefetch" href="/documentation/assets/js/32.a6900221.js"><link rel="prefetch" href="/documentation/assets/js/33.bbfb3084.js"><link rel="prefetch" href="/documentation/assets/js/34.0eb2f8aa.js"><link rel="prefetch" href="/documentation/assets/js/35.76c29241.js"><link rel="prefetch" href="/documentation/assets/js/36.dfcc07a1.js"><link rel="prefetch" href="/documentation/assets/js/37.173a8112.js"><link rel="prefetch" href="/documentation/assets/js/38.b86fac79.js"><link rel="prefetch" href="/documentation/assets/js/39.a7d50afe.js"><link rel="prefetch" href="/documentation/assets/js/40.0415492d.js"><link rel="prefetch" href="/documentation/assets/js/41.5ef681df.js"><link rel="prefetch" href="/documentation/assets/js/42.fdd80522.js"><link rel="prefetch" href="/documentation/assets/js/43.03b496f2.js"><link rel="prefetch" href="/documentation/assets/js/44.3f55a367.js"><link rel="prefetch" href="/documentation/assets/js/45.6746c3dc.js"><link rel="prefetch" href="/documentation/assets/js/46.ff6bc353.js"><link rel="prefetch" href="/documentation/assets/js/47.53b7147a.js"><link rel="prefetch" href="/documentation/assets/js/48.31a883aa.js"><link rel="prefetch" href="/documentation/assets/js/49.18bd1a60.js"><link rel="prefetch" href="/documentation/assets/js/50.9b6079cd.js"><link rel="prefetch" href="/documentation/assets/js/51.b67aee1b.js"><link rel="prefetch" href="/documentation/assets/js/52.62bc63b6.js"><link rel="prefetch" href="/documentation/assets/js/53.2c567c55.js"><link rel="prefetch" href="/documentation/assets/js/54.6cc10d25.js"><link rel="prefetch" href="/documentation/assets/js/55.7faca13f.js"><link rel="prefetch" href="/documentation/assets/js/56.0b06ad54.js"><link rel="prefetch" href="/documentation/assets/js/57.a87c48df.js"><link rel="prefetch" href="/documentation/assets/js/58.1c6547d9.js"><link rel="prefetch" href="/documentation/assets/js/59.06f908d7.js"><link rel="prefetch" href="/documentation/assets/js/60.b5156b8d.js"><link rel="prefetch" href="/documentation/assets/js/61.1d5cafa9.js"><link rel="prefetch" href="/documentation/assets/js/62.ccacebe2.js"><link rel="prefetch" href="/documentation/assets/js/63.66946dde.js"><link rel="prefetch" href="/documentation/assets/js/64.d53bdeb7.js"><link rel="prefetch" href="/documentation/assets/js/65.0cd2da1f.js"><link rel="prefetch" href="/documentation/assets/js/66.03059dce.js"><link rel="prefetch" href="/documentation/assets/js/67.6f988923.js"><link rel="prefetch" href="/documentation/assets/js/68.303c1a05.js"><link rel="prefetch" href="/documentation/assets/js/69.3f4ed952.js"><link rel="prefetch" href="/documentation/assets/js/70.531d76be.js"><link rel="prefetch" href="/documentation/assets/js/71.ab3e74fc.js">
|
|
<link rel="stylesheet" href="/documentation/assets/css/styles.a8210063.css"><link rel="stylesheet" href="/documentation/assets/css/1.styles.77d89b12.css"><link rel="stylesheet" href="/documentation/assets/css/2.styles.08038ddb.css">
|
|
</head>
|
|
<body>
|
|
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/documentation/" class="home-link router-link-active"><!----> <span class="site-name">
|
|
Strapi Docs
|
|
</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"> <a href="https://github.com/strapi/strapi" target="_blank" rel="noopener noreferrer" class="repo-link">
|
|
GitHub
|
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"> <a href="https://github.com/strapi/strapi" target="_blank" rel="noopener noreferrer" class="repo-link">
|
|
GitHub
|
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <div><select class="version-selector"><option value="/3.x.x/">Version 3.x.x</option><option value="/1.x.x/" selected="selected">Version 1.x.x</option></select></div> <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>UsefulLinks</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/documentation/1.x.x/" class="sidebar-link">Introduction</a></li><li><a href="https://strapi.io" class="sidebar-link">Strapi Website</a></li><li><a href="https://github.com/strapi/strapi" class="sidebar-link">GitHub Repository</a></li><li><a href="https://github.com/strapi/strapi/blob/master/CONTRIBUTING.md" class="sidebar-link">Contribution Guide</a></li></ul></div></li><li><a href="/documentation/1.x.x/admin.html" class="sidebar-link">Admin</a></li><li><a href="/documentation/1.x.x/configuration.html" class="sidebar-link">Configuration</a></li><li><a href="/documentation/1.x.x/email.html" class="sidebar-link">Email</a></li><li><a href="/documentation/1.x.x/introduction.html" class="active sidebar-link">Introduction</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/documentation/1.x.x/introduction.html#getting-started" class="sidebar-link">Getting Started</a></li><li class="sidebar-sub-header"><a href="/documentation/1.x.x/introduction.html#alternatives" class="sidebar-link">Alternatives</a></li><li class="sidebar-sub-header"><a href="/documentation/1.x.x/introduction.html#key-features" class="sidebar-link">Key-features</a></li></ul></li><li><a href="/documentation/1.x.x/queries.html" class="sidebar-link">Query Interface</a></li><li><a href="/documentation/1.x.x/response.html" class="sidebar-link">Response</a></li><li><a href="/documentation/1.x.x/sessions.html" class="sidebar-link">Sessions</a></li><li><a href="/documentation/1.x.x/testing.html" class="sidebar-link">Testing</a></li><li><a href="/documentation/1.x.x/views.html" class="sidebar-link">Views</a></li><li><a href="/documentation/1.x.x/blueprints.html" class="sidebar-link">Blueprints</a></li><li><a href="/documentation/1.x.x/context.html" class="sidebar-link">Context</a></li><li><a href="/documentation/1.x.x/graphql.html" class="sidebar-link">GraphQL</a></li><li><a href="/documentation/1.x.x/logging.html" class="sidebar-link">Logging</a></li><li><a href="/documentation/1.x.x/router.html" class="sidebar-link">Router</a></li><li><a href="/documentation/1.x.x/upload.html" class="sidebar-link">Upload</a></li><li><a href="/documentation/1.x.x/cli.html" class="sidebar-link">CLI</a></li><li><a href="/documentation/1.x.x/customization.html" class="sidebar-link">Customization</a></li><li><a href="/documentation/1.x.x/internationalization.html" class="sidebar-link">Internationalization</a></li><li><a href="/documentation/1.x.x/models.html" class="sidebar-link">Models</a></li><li><a href="/documentation/1.x.x/request.html" class="sidebar-link">Request</a></li><li><a href="/documentation/1.x.x/services.html" class="sidebar-link">Services</a></li><li><a href="/documentation/1.x.x/users.html" class="sidebar-link">Users</a></li></ul> </div> <div class="page"><div class="content"><h1 id="introduction"><a href="#introduction" aria-hidden="true" class="header-anchor">#</a> Introduction</h1> <hr> <p>Important Note: <strong>Strapi 1.x is on maintenance only</strong>. Development focuses on the upcoming Strapi 3.0.</p> <hr> <p>Strapi is an open-source Node.js rich framework for building applications and services.</p> <p>Strapi enables developers to focus on writing reusable application logic instead of spending time
|
|
building infrastructure. It is designed for building practical, production-ready Node.js applications
|
|
in a matter of hours instead of weeks.</p> <p>The framework sits on top of <a href="http://koajs.com/" target="_blank" rel="noopener noreferrer">Koa<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>. Its ensemble of small modules work
|
|
together to provide simplicity, maintainability, and structural conventions to Node.js applications.</p> <h2 id="getting-started"><a href="#getting-started" aria-hidden="true" class="header-anchor">#</a> Getting Started</h2> <h3 id="installation"><a href="#installation" aria-hidden="true" class="header-anchor">#</a> Installation</h3> <p>Install the latest stable release with the npm command-line tool:</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ <span class="token function">npm</span> <span class="token function">install</span> strapi -g
|
|
</code></pre></div><h3 id="create-your-first-project"><a href="#create-your-first-project" aria-hidden="true" class="header-anchor">#</a> Create your first project</h3> <p>You now are able to use the Strapi CLI. Simply create your first application and start the server:</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi new <span class="token operator"><</span>appName<span class="token operator">></span>
|
|
$ <span class="token function">cd</span> <span class="token operator"><</span>appName<span class="token operator">></span>
|
|
$ strapi start
|
|
</code></pre></div><p>The default home page is accessible at <a href="http://localhost:1337/" target="_blank" rel="noopener noreferrer">http://localhost:1337/<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>.</p> <h3 id="create-your-first-api"><a href="#create-your-first-api" aria-hidden="true" class="header-anchor">#</a> Create your first API</h3> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi generate api <span class="token operator"><</span>apiName<span class="token operator">></span>
|
|
</code></pre></div><p>For example, you can create a <code>car</code> API with a name (<code>name</code>), year (<code>year</code>) and
|
|
the license plate (<code>license</code>) with:</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi generate api car name:string year:integer license:string
|
|
</code></pre></div><h2 id="alternatives"><a href="#alternatives" aria-hidden="true" class="header-anchor">#</a> Alternatives</h2> <h3 id="dry-application"><a href="#dry-application" aria-hidden="true" class="header-anchor">#</a> Dry Application</h3> <p>Note that you can generate a dry application using the <code>dry</code> option:</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi new <span class="token operator"><</span>appName<span class="token operator">></span> --dry
|
|
</code></pre></div><p>This will generate a Strapi application without:</p> <ul><li>the built-in <code>user</code>, <code>email</code> and <code>upload</code> APIs,</li> <li>the <code>grant</code> hook,</li> <li>the open-source admin panel,</li> <li>the Waterline ORM (<code>waterline</code> and <code>blueprints</code> hooks disabled),</li> <li>the Strapi Studio connection (<code>studio</code> hook disabled).</li></ul> <p>This feature allows you to only use Strapi for your HTTP server structure if you want to.</p> <h3 id="create-an-api-via-the-strapi-studio"><a href="#create-an-api-via-the-strapi-studio" aria-hidden="true" class="header-anchor">#</a> Create an API via the Strapi Studio</h3> <p>The Strapi Studio allows you to easily build and manage your application environment
|
|
thanks to a powerful User Interface.</p> <p>Log into the Strapi Studio with your user account (<a href="http://studio.strapi.io" target="_blank" rel="noopener noreferrer">http://studio.strapi.io<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>)
|
|
and follow the instructions to start the experience.</p> <h3 id="link-to-the-strapi-studio"><a href="#link-to-the-strapi-studio" aria-hidden="true" class="header-anchor">#</a> Link to the Strapi Studio</h3> <blockquote><p>We advise you to use our Studio to build APIs. To do so, you need to create a Strapi account.
|
|
<a href="http://studio.strapi.io" target="_blank" rel="noopener noreferrer">Go to the Strapi Studio to signup<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>.
|
|
Studio is dedicated to developers to build applications without writing
|
|
any single line of code thanks to its powerful set of tools.</p></blockquote> <p>After creating an account on the Strapi Studio, you are able to link your machine to your
|
|
Strapi Studio account to get access to all features offered by the Strapi ecosystem.
|
|
Use your Strapi account credentials.</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi login
|
|
</code></pre></div><h2 id="key-features"><a href="#key-features" aria-hidden="true" class="header-anchor">#</a> Key-features</h2> <h3 id="_100-javascript"><a href="#_100-javascript" aria-hidden="true" class="header-anchor">#</a> 100% JavaScript</h3> <p>Building on top of Strapi means your application is written entirely in JavaScript,
|
|
the language you and your team are already using in the browser.</p> <p>Since you spend less time context-shifting, you're able to write code in a more consistent style,
|
|
which makes development more productive.</p> <p>The entire Strapi framework is written in ES2015.</p> <h3 id="getting-started-quickly"><a href="#getting-started-quickly" aria-hidden="true" class="header-anchor">#</a> Getting started quickly</h3> <p>Strapi provides a robust layer for fundamental web applications to help you write your business
|
|
logic, without obscuring Node.js features that you know and love. Our goal is to make writing
|
|
business logic much easier than other frameworks.</p> <h3 id="auto-generate-rest-apis"><a href="#auto-generate-rest-apis" aria-hidden="true" class="header-anchor">#</a> Auto-generate REST APIs</h3> <p>Strapi comes with a generator that help jumpstart your application's backend without writing any code. Just run:</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ strapi generate api car
|
|
</code></pre></div><p>and you'll get an API that lets you read, paginate, sort, filter, create, destroy, update,
|
|
and associate cars.</p> <h3 id="security"><a href="#security" aria-hidden="true" class="header-anchor">#</a> Security</h3> <p>We take security very seriously. This is why Strapi comes with several security layers that just work
|
|
depending on your needs. Strapi provides configuration for CORS, CSRF, CSP, X-Frame-Options, XSS, HSTS,
|
|
HTTPS, SSL, proxy, IP filtering and ships reusable security policies.</p> <p>No matter what you need to secure, Strapi is the right tool to make it right.</p> <h3 id="datastore-agnostic"><a href="#datastore-agnostic" aria-hidden="true" class="header-anchor">#</a> Datastore-agnostic</h3> <p>Strapi comes installed with a powerful ORM/ODM called Waterline, a datastore-agnostic tool that
|
|
dramatically simplifies interaction with one or more databases.</p> <p>It provides an abstraction layer on top of the underlying database, allowing you to easily query
|
|
and manipulate your data without writing vendor-specific integration code.</p> <p>Strapi offers a new take on the familiar relational model, aimed at making data modeling more practical.
|
|
You can do all the same things you might be used to (one-to-many, many-to-many), but you can also assign
|
|
multiple named associations per-model. Better yet, you can assign different models to different databases,
|
|
and your associations/joins will still work, even across NoSQL and relational boundries.</p> <p>Strapi has no problem implicitly/automatically joining a SQL table with a NoSQL collection and vice versa.</p> <h3 id="front-end-agnostic"><a href="#front-end-agnostic" aria-hidden="true" class="header-anchor">#</a> Front-end agnostic</h3> <p>Strapi is compatible with any front-end strategy; whether it's Angular, Backbone, Ember,
|
|
iOS, Android, Windows Phone, or something else that hasn't been invented yet.</p> <p>Plus it's easy to serve up the same API to be consumed by another web service or community of developers.</p> <h3 id="convention-over-configuration"><a href="#convention-over-configuration" aria-hidden="true" class="header-anchor">#</a> Convention over configuration</h3> <p>Convention over configuration is a consistent approach makes developing applications more
|
|
predictable and efficient for everybody involved.</p> <p>If anyone on your team has worked with frameworks, Strapi will feel pretty familiar.
|
|
Not only that, but they can look at a Strapi project and know, generally, how to code up the basic
|
|
patterns they've implemented over and over again in the past; whether their background.
|
|
What about your second application, or your third? Each time you create a new Strapi application,
|
|
you start with a sane, familiar boilerplate that makes you more productive.</p> <p>Configuration files give you extra opportunities for human error.</p> <p>In many cases, you'll even be able to recycle some of your code.</p> <h3 id="error-handling"><a href="#error-handling" aria-hidden="true" class="header-anchor">#</a> Error Handling</h3> <p>By default outputs all errors to <code>stderr</code> unless <code>NODE_ENV</code> is <code>test</code>.
|
|
To perform custom error-handling logic such as centralized logging you can add an "error" event listener:</p> <div class="language-js extra-class"><pre class="language-js"><code>strapi<span class="token punctuation">.</span>app<span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">'error'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>err<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|
strapi<span class="token punctuation">.</span>log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">'server error'</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
</code></pre></div><p>If an error in the req/res cycle and it is not possible to respond to the client,
|
|
the <code>Context</code> instance is also passed:</p> <div class="language-js extra-class"><pre class="language-js"><code>strapi<span class="token punctuation">.</span>app<span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">'error'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>err<span class="token punctuation">,</span> ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|
strapi<span class="token punctuation">.</span>log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">'server error'</span><span class="token punctuation">,</span> err<span class="token punctuation">,</span> ctx<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
</code></pre></div><p>When an error occurs and it is still possible to respond to the client,
|
|
aka no data has been written to the socket, Strapi will respond appropriately with
|
|
a 500 "Internal Server Error". In either case an app-level "error" is emitted for logging purposes.</p> <h3 id="different-environments"><a href="#different-environments" aria-hidden="true" class="header-anchor">#</a> Different environments</h3> <p>Strapi has built in support for the idea of having a different set of settings for each environment.
|
|
Real applications have this too, but often the framework around them doesn't accommodate it and
|
|
you end up having to swap configuration files in and out to achieve the same effect.</p> <h3 id="loose-coupling"><a href="#loose-coupling" aria-hidden="true" class="header-anchor">#</a> Loose coupling</h3> <p>Strapi is flexible enough to allow you to explore and create when you have the time to but also
|
|
provides automation tools when you don't.</p></div> <div class="page-edit"><div class="edit-link"><a href="https://github.com/strapi/strapi/edit/master/docs/1.x.x/introduction.md" target="_blank" rel="noopener noreferrer">Improve this page</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <!----></div> <div class="page-nav"><p class="inner"><span class="prev">
|
|
← <a href="/documentation/1.x.x/email.html" class="prev">
|
|
Email
|
|
</a></span> <span class="next"><a href="/documentation/1.x.x/queries.html">
|
|
Query Interface
|
|
</a> →
|
|
</span></p></div> </div></div></div>
|
|
<script src="/documentation/assets/js/14.7cfd4cb8.js" defer></script><script src="/documentation/assets/js/app.a8210063.js" defer></script>
|
|
</body>
|
|
</html>
|