我遵循了官方教程,并成功使用 pm2 运行了一个小脚本来启动 strapi。
const strapi = require('strapi');
strapi().start();
但是自动重新加载已关闭,并且管理面板不允许我编辑任何内容类型?我应该如何在开启自动重新加载的情况下启动?
Strapi 弹出了一个警报,告诉我使用"yarn develop"命令启动它,但它没有通过 pm2,当我注销终端时它被击落。所以我认为这不是实际使用的正确启动方式。
如果 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
命令启动它
要修复自动重新加载问题,请使用yarn strapi dev
而不是yarn strapi
您无法在生产中编辑 Strapi 内容类型。您只能在开发中执行此操作。查看此讨论:https://forum.strapi.io/t/the-autoreload-feature-is-required-to-use-this-plugin-start-your-server-with-strapi-develop/12207/25