我想创建一个Microsoft Teams选项卡作为Web应用程序。我已经完成了初始设置并开始运行。 (使用Yo团队)现在,我想向Azure函数发送一个http(s)请求。所以我添加了一个后期中间件 函数到我的 server.ts ,应该调用函数。
express.post("/createteamswiki", (req, res) => {
https.request("my.function.url", { method : "POST" }, () => {
});
res.status(200);
res.json("Oki");
});
在我的 WikiConfig.ts 中,我更改了save方法来发送请求。我尝试使用vanilla-js和以下模块: http 和 https 。使用vanilla-js可以发送请求,但在Chrome开发工具中将其标记为 ERR_FAILED 。这些库根本不发送任何东西。因此,永远不会调用成功回调,因此也不会调用 saveEvent.notifySuccess(); 。因此,配置窗口保持不变并报告错误。
public async componentWillMount() {
this.updateTheme(this.getQueryVariable("theme"));
if (await this.inTeams()) {
microsoftTeams.initialize();
microsoftTeams.getContext((context: microsoftTeams.Context) => {
this.setState({
value: context.entityId
});
this.updateTheme(context.theme);
microsoftTeams.settings.setValidityState(true);
microsoftTeams.appInitialization.notifySuccess();
});
microsoftTeams.settings.registerOnSaveHandler((saveEvent: microsoftTeams.settings.SaveEvent) => {
// Calculate host dynamically to enable local debugging
const host = "https://" + window.location.host;
microsoftTeams.settings.setSettings({
contentUrl: host + "/sharepointWikiTab/?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}",
websiteUrl: host + "/sharepointWikiTab/?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}",
suggestedDisplayName: "Sharepoint Wiki",
removeUrl: host + "/sharepointWikiTab/remove.html?theme={theme}",
entityId: this.state.value
});
microsoftTeams.getContext((context: microsoftTeams.Context) => {
this.setState({
value: context.teamSiteUrl || ""
});
https.request("https://" + window.location.host + "/createteamswiki?code=gM6t7bov41tkw1ZTxGZUasY1WQH7UgrONp4OyoVzaYaFtFBTBwZcRQ==&team=" + context.teamSiteUrl, (res) => {
this.setState({
value: "Awesome it works..."
});
saveEvent.notifySuccess();
});
});
// saveEvent.notifySuccess();
});
} else {
}
}
我找不到任何原因,因为请求调用了node.js服务器,该服务器成功提供了http文件。
答案 0 :(得分:1)
我认为这是由于跨源请求引起的。您可以检查请求标头,看看是否启用了CORS,还可以检查清单中是否将URL添加到了validDomain []数组中