我是 IBM 云的新手,我正在嘗試構(gòu)建一個應(yīng)用程序,我可以在其中編寫文本,按下按鈕,然后由返回 JSON 的服務(wù)音分析器分析該文本,以便我可以顯示它。我創(chuàng)建了該服務(wù)的一個實例,并使用服務(wù)上的“連接”選項卡將其連接到我的應(yīng)用程序(工具鏈)。我的應(yīng)用程序的 app.js 文件中也有此代碼:const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');const { IamAuthenticator } = require('ibm-watson/auth');const toneAnalyzer = new ToneAnalyzerV3({ version: '2019-10-10', authenticator: new IamAuthenticator({ apikey: [API key found in service credentials], }), url: [API url found in service credentials],});app.get('/', function(req, res) { res.render('index');});app.post('/api/tone', async function(req, res, next) { try { const { result } = await toneAnalyzer.tone(req.body); res.json(result); } catch (error) { next(error); }});問題是,當我在 javascript 上進行以下調(diào)用時:$.post( "/api/tone", {text: textInput}, function(data){ console.log(data); });我收到錯誤:500(內(nèi)部服務(wù)器錯誤)。有人知道我做錯了什么嗎?
如何將服務(wù)連接到 Cloud Foundry 應(yīng)用程序?
慕哥9229398
2023-07-06 18:24:12