Admin panel customization

Admin extension

The admin panel is a node_module that is similar to a plugin, with the slight difference that it encapsulates all the installed plugins of your application.

To extend this package you will have to create an admin folder at the root of your application.

In this folder you will be able to override admin files and functions.

Customization options

The administration panel can be customized according to your needs, so you can make it reflect your identity.

WARNING

To apply your changes you need to rebuild your admin panel

Change access URL

By default, the administration panel is exposed via http://localhost:1337/adminAdmin panel customization - 图1 (opens new window). However, for security reasons, you can easily update this path. For more advanced settings please see the server config documentation.

Path — ./config/server.js.

  1. module.exports = ({ env }) => ({
  2. host: env('HOST', '0.0.0.0'),
  3. port: env.int('PORT', 1337),
  4. admin: {
  5. url: '/dashboard',
  6. },
  7. });

The panel will be available through http://localhost:1337/dashboardAdmin panel customization - 图2 (opens new window) with the configuration above.

Development mode

To enable the front-end development mode you need to start your application using the --watch-admin flag.

  1. cd my-app
  2. strapi develop --watch-admin

With this option you can do the following:

Customize the strapi-admin package

All files added in my-app/admin/src/ will either be replaced or added

Example: Changing the available locales of your application

  1. # Create both the admin and admin/src/translations folders
  2. cd my-app && mkdir -p admin/src/translations
  3. # Change the available locales of the administration panel
  4. touch admin/src/i18n.js
  5. # Change the import and exports of the translations files
  6. touch admin/src/translations/index.js

Path - my-app/admin/src/translations/index.js

  1. import en from './en.json';
  2. import fr from './fr.json';
  3. const trads = {
  4. en,
  5. fr,
  6. };
  7. export const languageNativeNames = {
  8. en: 'English',
  9. fr: 'Français',
  10. };
  11. export default trads;

TIP

With this modification only English and French will be available in your admin

Customize a plugin

Similarly to the back-end override system, any file added in my-app/extensions/<plugin-name>/admin/ will be copied and used instead of the original one (use with care).

Example: Changing the current WYSIWYG

  1. cd my-app/extensions
  2. # Create the content manager folder
  3. mkdir content-manager && cd content-manager
  4. # Create the admin folder
  5. mkdir -p admin/src
  6. # Create the components folder and the WysiwygWithErrors one
  7. cd admin/src && mkdir -p components/WysiwygWithErrors
  8. # Create the index.js so the original file is overridden
  9. touch components/WysiwygWithErrors/index.js

Path - my-app/extensions/content-manager/admin/src/components/WysiwygWithErrors/index.js

  1. import React from 'react';
  2. import MyNewWYSIWYG from 'my-awesome-lib';
  3. // This is a dummy example
  4. const WysiwygWithErrors = props => <MyNewWYSIWYG {...props} />;
  5. export default WysiwygWithErrors;

Styles

The AdminUI package source can be easily found in ./node_modules/strapi-admin/src/.

For example, to change the top-left displayed admin panel’s color, copy the ./node_modules/strapi-admin/admin/src/components/LeftMenu/LeftMenuHeader folder to ./admin/src/components/LeftMenu/LeftMenuHeader (create these folders if they don’t exist) and change the styles inside ./admin/src/components/LeftMenu/LeftMenuHeader/Wrapper.js.

Thus, you are replacing the files that would normally be in node_modules/strapi-admin/admin/src and directing them to admin/src/some/file/path.

To apply your changes you need to rebuild your admin panel

  1. npm run build

Logo

To change the top-left displayed admin panel’s logo, add your custom image at ./admin/src/assets/images/logo-strapi.png.

To change the login page’s logo, add your custom image at ./admin/src/assets/images/logo_strapi.png.

TIP

make sure the size of your image is the same as the existing one (434px x 120px).

Tutorial videos

To disable the information box containing the tutorial videos, create a file at ./admin/src/config.js

Add the following configuration:

  1. export const LOGIN_LOGO = null;
  2. export const SHOW_TUTORIALS = false;
  3. export const SETTINGS_BASE_URL = '/settings';
  4. export const STRAPI_UPDATE_NOTIF = true;

Changing the host and port

By default, the front-development server runs on localhost:8000. However, you can change this setting by updating the following configuration:

Path — ./config/server.js.

  1. module.exports = ({ env }) => ({
  2. host: env('HOST', '0.0.0.0'),
  3. port: env.int('PORT', 1337),
  4. admin: {
  5. host: 'my-host', // only used along with `strapi develop --watch-admin` command
  6. port: 3000, // only used along with `strapi develop --watch-admin` command
  7. },
  8. });

Build

To build the administration, run the following command from the root directory of your project.

  1. yarn build
  1. npm run build
  1. strapi build

This will replace the folder’s content located at ./build. Visit http://localhost:1337/adminAdmin panel customization - 图3 (opens new window) to make sure your updates have been taken into account.

Custom Webpack Config

In order to extend the usage of webpack, you can define a function that extends its config inside admin/admin.config.js, like so:

  1. module.exports = {
  2. webpack: (config, webpack) => {
  3. // Note: we provide webpack above so you should not `require` it
  4. // Perform customizations to webpack config
  5. // Important: return the modified config
  6. config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//));
  7. return config;
  8. },
  9. };

Deployment

The administration is nothing more than a React front-end application calling an API. The front-end and the back-end are independent and can be deployed on different servers which brings us to different scenarios:

  1. Deploy the entire project on the same server.
  2. Deploy the administration panel on another server (AWS S3, Azure, etc) than the API.

Let’s dive into the build configurations for each case.

Deploy the entire project on the same server.

You don’t need to touch anything in your configuration file. This is the default behavior and the build configuration will be automatically set. The server will start on the defined port and the administration panel will be accessible through http://yourdomain.com:1337/dashboard.

You might want to change the path to access the administration panel. Here is the required configuration to change the path:

Path — ./config/server.js.

  1. module.exports = ({ env }) => ({
  2. host: env('HOST', '0.0.0.0'),
  3. port: env.int('PORT', 1337),
  4. admin: {
  5. url: '/dashboard', // We change the path to access to the admin (highly recommended for security reasons).
  6. },
  7. });

You have to rebuild the administration panel to make this work. Build instructions.

Deploy the administration panel on another server (AWS S3, Azure, etc) than the API.

It’s very common to deploy the front-end and the back-end on different servers. Here is the required configuration to handle this case:

Path — ./config/server.js.

  1. module.exports = ({ env }) => ({
  2. host: env('HOST', '0.0.0.0'),
  3. port: env.int('PORT', 1337),
  4. url: 'http://yourbackend.com',
  5. admin: {
  6. url: '/', // Note: The administration will be accessible from the root of the domain (ex: http://yourfrontend.com/)
  7. serveAdminPanel: false, // http://yourbackend.com will not serve any static admin files
  8. },
  9. });

After running yarn build with this configuration, the folder build will be created/overwritten. You can then use this folder to serve it from another server with the domain of your choice (ex: http://yourfrontend.com).

The administration URL will then be http://yourfrontend.com and every request from the panel will hit the backend at http://yourbackend.com.

NOTE

If you add a path to the url option, it won’t prefix your app. To do so, you need to also use a proxy server like Nginx. More here.

Forgot Password Email

Customize forgot password email

You may want to customize the forgot password email. You can do it by providing your own template (formatted as a lodash templateAdmin panel customization - 图4 (opens new window)).

The template will be compiled with the following variables: url, user.email, user.username, user.firstname, user.lastname.

Example

Path - ./config/servers.js

  1. const forgotPasswordTemplate = require('./email-templates/forgot-password');
  2. module.exports = ({ env }) => ({
  3. // ...
  4. admin: {
  5. // ...
  6. forgotPassword: {
  7. from: 'support@mywebsite.fr',
  8. replyTo: 'support@mywebsite.fr',
  9. emailTemplate: forgotPasswordTemplate,
  10. },
  11. // ...
  12. },
  13. // ...
  14. });

Path - ./config/email-templates/forgot-password.js

  1. const subject = `Reset password`;
  2. const html = `<p>Hi <%= user.firstname %></p>
  3. <p>Sorry you lost your password. You can click here to reset it: <%= url %></p>`;
  4. const text = `Hi <%= user.firstname %>
  5. Sorry you lost your password. You can click here to reset it: <%= url %>`;
  6. module.exports = {
  7. subject,
  8. text,
  9. html,
  10. };