首页 > 解决方案 > 如何使用 pm2 启动带有 AutoReload 的strapi?

问题描述

我按照官方教程成功使用pm2运行了一个小脚本来启动strapi。

const strapi = require('strapi');
strapi().start();

但是 AutoReload 已关闭,并且管理面板不允许我编辑任何内容类型?我应该如何启动 AutoReload?

Strapi 弹出一个警报,告诉我用“yarn develop”命令启动它,但它没有通过 pm2,当我注销终端时它被击落。所以我认为这不是在实际使用中启动的正确方法。

标签: pm2strapi

解决方案


如果 strpi 要求您使用yarn develop,则表示;您不在开发环境中,因此您无法在 Api 中进行更改。

您需要在您的根文件夹中使用一个名为生态系统.config.js 的特殊配置文件,并且您需要设置autorestart: true.

module.exports = {
  apps : [{
    name: 'nameofyourapp',
    script: 'server.js',

    // Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
    // args: 'one two',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
// not production or staging
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],

  // deploy : {
  //   production : {
  //     user : 'node',
  //     host : '212.83.163.1',
  //     ref  : 'origin/master',
  //     repo : 'git@github.com:repo.git',
  //     path : '/var/www/production',
  //     'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
  //   }
  // }
};

然后用pm2 start ecosystem.config.js命令启动它


推荐阅读