在nodejs中重启heroku dyno
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25618792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Restart heroku dyno in nodejs
提问by user1660601
I want to restart a nodejs app to change its ip. How would I do this within the app itself? I have tried forcing a crash however if the app crashes twice within ten minutes, then heroku will restart the dyno ten minutes after the first crash.
我想重新启动 nodejs 应用程序以更改其 ip。我将如何在应用程序本身中执行此操作?我曾尝试强制崩溃,但是如果应用程序在十分钟内崩溃两次,那么 heroku 将在第一次崩溃后十分钟重新启动 dyno。
采纳答案by brennebeck
回答by gaelgillard
If you have the Heroku CLI installed, you can run heroku restartin the folder of your application or run heroku restart --app application_name.
如果您安装了 Heroku CLI,则可以heroku restart在应用程序的文件夹中运行或运行heroku restart --app application_name.
If you don't have it installed, you can find information about it here.
回答by Dhyey
回答by Jason
Using the Heroku v3 APIit is possible using the request node module
使用Heroku v3 API可以使用请求节点模块
var token = 'youAPIKeyHere';
var appName = 'yourAppName here';
var dynoName = 'yourDynoHere';
var request = require('request');
request.delete(
{
url: 'https://api.heroku.com/apps/' + appName + '/dynos/',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer ' + token
}
},
function(error, response, body) {
// Do stuff
}
);
There is also a node wrapperthat provides a similar experience, but is poorly documented and requires an understanding of the v3 APIanyway
还有一个提供类似体验的节点包装器,但文档不全,无论如何都需要了解v3 API
var token = 'youAPIKeyHere';
var appName = 'yourAppName here';
var dynoName = 'yourDynoHere';
var Heroku = require('heroku-client');
var heroku = new Heroku({ token: token });
heroku .delete('/apps/' + appName + '/dynos/' + dynoName)
.then( x => console.log(x) );
I also found it useful to experiment in browser with this code
我还发现使用此代码在浏览器中进行实验很有用
var token = 'youAPIKeyHere';
var appName = 'yourAppName here';
var dynoName = 'yourDynoHere';
var xhr = new XMLHttpRequest();
xhr.open(
'DELETE',
'https://api.heroku.com/apps/' + appName + '/dynos/' + dynoName
);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Accept', 'application/vnd.heroku+json; version=3');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.onload = function() {
console.log(xhr.response);
};
xhr.send();
I personally did find using the delete method a bit concerning. Caution should be taken with using the
deletemethod and the/apps/$$appName$$endpoint alone will delete the app. This is from personal experienceFor any of the above, if you omit the dyno name, you will restart all dynos under the app
我个人确实发现使用删除方法有点令人担忧。使用该
delete方法时应谨慎,/apps/$$appName$$仅端点将删除该应用程序。这是个人经验对于以上任何一个,如果您省略dyno名称,您将重新启动应用程序下的所有dyno


