简体   繁体   English

使用PM2运行swagger模拟服务器

[英]Running swagger mock server using pm2

I am using Sails.js and swagger. 我正在使用Sails.js和招摇。 To start the mock server I run 要启动模拟服务器,请运行

swagger project start -m

and it works fine, but it requires keeping the terminal open. 并且工作正常,但是需要保持终端打开。 So to daemonize I tried pm2 or even forever but they don't work (using Linux). 因此,为了实现守护进程,我尝试了pm2或什至永远使用,但它们不起作用(使用Linux)。 The process.json for pm2 is: pm2的process.json是:

{
    "apps": [
        {
            "name": "my-web-api",
            "script": "/usr/lib/node_modules/swagger/bin/swagger.js",
            "watch": true,
            "instances": "max",
            "exec_mode": "cluster",
            "args": "['project', 'start', '-m']"
        }
    ]
}

The command: 命令:

p2 start process.json

doesn't start the server. 无法启动服务器。 pm2 logs command shows pm2 logs命令显示

PM2        | Script /usr/lib/node_modules/swagger/bin/swagger.js had too many unstable restarts (16). Stopped. "errored"

If you are having issues with pm2 still, check out prism http://stoplight.io/platform/prism . 如果pm2仍然有问题,请查看棱镜http://stoplight.io/platform/prism You can download it here for free: https://github.com/stoplightio/prism 您可以在这里免费下载: https//github.com/stoplightio/prism

This command line is all you need: 该命令行是您所需的全部:

./prism run --mock --list --spec ./prism运行--mock --list --spec

The mock server will return dynamic response based on the swagger spec. 模拟服务器将基于swagger规范返回动态响应。 If examples are provided in the spec, prism will return them, if not it will generate dummy data based on the spec. 如果规范中提供了示例,则棱镜将返回它们,否则,它将根据规范生成伪数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM