【问题标题】:how to use pm2 to launch strapi with AutoReload on?如何使用 pm2 启动带有 AutoReload 的strapi?
【发布时间】:2021-01-16 15:47:56
【问题描述】:

按照官方教程,成功使用pm2运行小脚本启动strapi。

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

但自动重载已关闭,并且管理面板不允许我编辑任何内容类型?我应该如何在 AutoReload 开启的情况下启动?

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

【问题讨论】:

    标签: pm2 strapi


    【解决方案1】:

    如果strapi要求你使用yarn develop,它的意思是;您不在开发环境中,因此您无法在 Api 中进行更改。

    您需要在您的根文件夹中使用一个名为 ecosystem.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 命令启动它

    【讨论】:

    • 我相信“自动重启”的说法是针对 pm2 而不是针对strapi
    【解决方案2】:

    要修复自动重新加载问题,请使用 yarn strapi dev 而不是 yarn strapi

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2016-12-10
      • 2020-07-12
      • 2018-02-17
      相关资源
      最近更新 更多