我正在尝试将我的应用程序部署到 Heroku,但是我依赖于使用一些私有(private) git 存储库作为模块。我这样做是为了项目之间的代码重用,例如我有一个在多个应用程序中使用的自定义记录器。
"logger":"git+ssh://git@bitbucket.org..............#master"
问题是 Heroku 显然没有 ssh 访问此代码的权限。我在这个问题上找不到任何东西。理想情况下,Heroku 有一个公钥,我可以将其添加到模块中。
最佳答案
基本认证
GitHub 支持基本认证:
"dependencies" : {
"my-module" : "git+https://my_username:my_password@github.com/my_github_account/my_repo.git"
}
BitBucket 也是如此:
"dependencies" : {
"my-module": "git+https://my_username:my_password@bitbucket.org/my_bitbucket_account/my_repo.git"
}
但可能不需要在 package.json
中使用纯密码。
个人访问 token (GitHub)
为了使这个答案更加最新,我现在建议 using a personal access token在 GitHub 上,而不是用户名/密码组合。
你现在应该使用:
"dependencies" : {
"my-module" : "git+https://<username>:<token>@github.com/my_github_account/my_repo.git"
}
对于 Github,您可以在此处生成新 token :
https://github.com/settings/tokens
应用密码(Bitbucket)
应用密码主要用于提供与不支持双重身份验证的应用的兼容性,您也可以将其用于此目的。一、create an app password ,然后像这样指定您的依赖项:
"dependencies" : {
"my-module": "git+https://<username>:<app-password>@bitbucket.org/my_bitbucket_account/my_repo.git"
}
[已弃用] 团队 API key (Bitbucket)
对于 BitBucket,您可以在管理团队页面上生成一个 API key ,然后使用此 URL:
"dependencies" : {
"my-module" : "git+https://<teamname>:<api-key>@bitbucket.org/team_name/repo_name.git"
}
关于node.js - Heroku 上的 NPM 私有(private) git 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10869796/