简体   繁体   English

ibmcloud-appid: nodejs 如何进行本地开发 vs 在 IBM Cloud 中运行?

[英]ibmcloud-appid: nodejs how to do local development vs running in the IBM Cloud?

I am working with appid-serversdk-nodejs and I have the code working and everything works fine, both locally and in the IBM cloud.我正在使用appid-serversdk-nodejs并且我的代码可以正常工作并且一切正常,无论是在本地还是在 IBM 云中。

But I have to manually switch the APP-URL (localhost:3000 vs .eu-gb.mybluemix.net) I understand that I can do it without providing the passport settings, but how can I have one code base that works for:但是我必须手动切换 APP-URL (localhost:3000 vs .eu-gb.mybluemix.net) 我知道我可以在不提供护照设置的情况下做到这一点,但是我如何拥有一个适用于的代码库:

  • localdev test本地开发测试
  • instance in ibm cloud ibm 云中的实例
  • production instance in ibm cloud ibm 云中的生产实例

I am talking about this piece of code:我说的是这段代码:

// The redirectUri value can be supplied in three ways:
// 1. Manually in new WebAppStrategy({redirectUri: "...."})
// 2. As environment variable named redirectUri
// 3. If none of the above was supplied the App ID SDK will try to retrieve
// application_uri of the application running on IBM Cloud and append a
// default suffix "/ibm/bluemix/appid/callback"
passport.use(new WebAppStrategy({
tenantId: "removed",
clientId: "removed",
secret: "removed",
oauthServerUrl: "https://eu-gb.appid.cloud.ibm.com/oauth/v4/REMOVED"
redirectUri: "https://REMOVED.eu-gb.mybluemix.net" + CALLBACK_URL
//redirectUri: "http://localhost:3000" + CALLBACK_URL
}));

Update: I have moved the data to the .env file, but this doesn't solve my question.更新:我已将数据移至 .env 文件,但这并不能解决我的问题。

tenantId: process.env.APPID_tenantId,
clientId: process.env.APPID_clientId,
secret: process.env.APPID_secret,
oauthServerUrl: process.env.APPID_oauthServerUrl,
redirectUri: process.env.APPID_redirectUri + CALLBACK_URL

Now I have to change the .env file, which leads to a new commit and build.现在我必须更改 .env 文件,这会导致新的提交和构建。 I want to leverage the connection between APP-ID and our Node server in the IBM cloud.我想利用 APP-ID 和 IBM 云中的 Node 服务器之间的连接。

I am getting errors if I don't supply the redirectUri or the entire WebAppStrategy如果我不提供 redirectUri 或整个 WebAppStrategy,我会收到错误

You are doing the right thing (technically) with process.env.*, there are of course multiple other ways of doing it, but that's another subject (personally I utilize CUPS a lot in these situations, .env leads easily to a situations where you commit the secrets to version control)您正在使用 process.env.* 做正确的事情(技术上),当然还有多种其他方法可以做到,但这是另一个主题(我个人在这些情况下经常使用 CUPS,.env 很容易导致以下情况您将秘密提交给版本控制)

I'm sure you have given all the url:s as redirect uri:s at the App ID instance ( which would anyway give quite distinctive error if that was the problem ).我确定您已经在 App ID 实例中将所有 url:s 作为重定向 uri:s 提供了(如果这是问题,无论如何都会给出非常明显的错误)。

You're not sharing what errors are those, that you are getting, but there are a few things you can check.您没有分享您遇到的错误是什么,但是您可以检查一些事情。

a) The olders trick in the book - make some debug outputs on your logic to verify that the values you set as environment variables, are actually present at runtime. a) 书中较老的技巧 - 在您的逻辑上制作一些调试输出,以验证您设置为环境变量的值是否在运行时实际存在。

b) As you usually do https in cloud but http locally, you might need to set conditionally cookie: { secure: true } only for the cloud deployment, not locally. b) 由于您通常在云中使用 https 而在本地使用 http,您可能需要有条件地设置 cookie: { secure: true } 仅用于云部署,而不是本地。

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

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