久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

如何將fodi后端部署到cloudbase

157次閱讀
沒有評論

共計 3536 個字符,預計需要花費 9 分鐘才能閱讀完成。

這篇文章主要介紹了如何將 fodi 后端部署到 cloudbase,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓丸趣 TV 小編帶著大家一起了解一下。

上傳和修改后端邏輯:

用 cloudbase-cli 提交 backend-py:

{
  envId :  default-4gpm7vnrb911600e ,
  functionRoot :  functions ,
  functions : 
 [{
  name :  fodi , //fodi 就是 backend-py
  timeout : 6,
  runtime :  Python3.6 ,
  memorySize : 128,
  installDependency : true,
  handler :  index.main_handler 
 }]
}

以下保證要使用 https://xxxx.service.tcloudbase.com/fodi 形式的調用路徑 (后臺的接入路徑定義):

def router(event):
  對多個  api  路徑分發
  
 door =  https://  + event[headers][host]
 print(door: +door)
 func_path =   #event[requestContext][path] // 置空
 print(func_path: +func_path)
 
 api = event[path].replace(func_path, ).strip(/) 
 api_url = door +  /fodi  + event[path] // 加一個 fodi 串
 queryString = event[queryStringParameters] // 這里改
 body = None
 ......

弄好后,訪問上面的接入路徑,僅 /fodi,輸出 path error 和后面一長串東西就代表服務器搭建正常,

獲取 refresh token

然后就是那個 refreshtoken 的獲取,http://scfonedrive.github.io 已經掛掉了,我們可以自建,先在某網站下建一個 get.html:

html meta charset=utf-8 body h2 Error /h2 p Please set the  code refresh_token /code  in environments br 
  a href=  id= a1 Get a refresh_token /a 
  br code allow javascript /code 
  script 
 url=window.location.href;
 if (url.substr(-1)!= / ) url+= / 
 url= https://login.partner.microsoftonline.cn/common/oauth3/v2.0/authorize?scope=https%3A%2F%2Fmicrosoftgraph.chinacloudapi.cn%2FFiles.ReadWrite.All+offline_access response_type=code client_id=04c3ca0b-8d07-4773-85ad-98b037d25631 redirect_uri=https://scfonedrive.github.io state= +encodeURIComponent(url);
 document.getElementById(a1).href=url;
 //window.open(url, _blank 
  /script 
  /p /body /html 
如果是國際版 url 換成:
 url= https://login.microsoftonline.com/common/oauth3/v2.0/authorize?scope=https%3A%2F%2Fgraph.microsoft.com%2FFiles.ReadWrite.All+offline_access response_type=code client_id=4da3e7f2-bf6d-467c-aaf0-578078f0bf7c redirect_uri=https://scfonedrive.github.io state= +encodeURIComponent(url);

再在根下建一個 index.html

html xmlns= http://www.w3.org/1999/xhtml  xml:lang= en 
 head 
 title OneManager jump page /title 
 /head 
 body 
 a id= direct No link here! /a br 
 If not auto jump, click the link to jump. br 
 如果長時間未跳轉,請點擊上方鏈接繼續安裝。br 
 label id= test1 /label 
 script 
  var q = new Array();
 var query = window.location.search.substring(1);
 //document.getElementById(test1).innerHTML=query;
 var vars = query.split(for (var i=0;i vars.length;i++) {var pair = vars[i].split( = 
 q[pair[0]]=pair[1];
 var url = q[ state 
 var code = q[ code 
 if (!!url   !!code) {url = decodeURIComponent(url);
 if (url.substr(-1)!= / ) url+= / 
 var lasturl = url+ ?authorization_code code= +code;
 document.getElementById(direct).innerText = lasturl;
 document.getElementById(direct).href = lasturl;
 window.location = lasturl;
 } else {
 var str= Error!  有誤!if (!url) str+= No url! url 參數為空!if (!code) str+= No code from MS!  微軟 code 為空!document.getElementById(test1).innerHTML=str+ br +decodeURIComponent(query);
 alert(str);
 /script 
 /body 
 /html

把 get 中 scfonedrive.github.io 換成你的 index.html 所在的網站地址,(之后保證把 py 后端中用于認證的地址和那個 clientid,clientsecret 替換用你自己新建的一個,具體方法見我前面的一些文章)

調用后結果顯示在 url 中(整個頁面顯示 404 是沒有處理結果的 php 后端,除非你把 https://github.com/qkqpttgf/OneDrive_SCF 部署在 index.html 所在的網站),分辨復制即可。

安排好后端和 refreshtoken 后,調用接入路徑 /fodi/fodi/,輸出看到其輸出的加密的 json 結果,就代表 refreshtoken 也正常了。開始部署前端,可以另外一個網站,能托管 html 的就行。也可以在后端另起一函數,部署如下 index.py:

#!/usr/bin/env python
# -*- coding:utf-8 -*-

def main_handler(event, context):  f = open(./front.html , encoding= utf-8)  html = f.read()  return {   isBase64Encoded : False,   statusCode : 200,   headers : {Content-Type :  text/html; charset=utf-8},   body : html  }

front.html 當然是配置好的那個前端文件。

如果你 fodi 前端調用發生 for each,length 之類的提示錯誤,往往是 refresh token 沒獲取對。如果發生跨域錯誤(chrome f12 可看到),則在后端面板中需要配置一條客戶端網站的安全域名。

感謝你能夠認真閱讀完這篇文章,希望丸趣 TV 小編分享的“如何將 fodi 后端部署到 cloudbase”這篇文章對大家有幫助,同時也希望大家多多支持丸趣 TV,關注丸趣 TV 行業資訊頻道,更多相關知識等著你來學習!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-25發表,共計3536字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 阳朔县| 诸暨市| 华容县| 宜川县| 友谊县| 天长市| 墨竹工卡县| 安仁县| 定日县| 永城市| 天峻县| 滦平县| 武陟县| 宿迁市| 龙井市| 海口市| 巨鹿县| 镇沅| 札达县| 宜兰市| 崇阳县| 阳曲县| 图们市| 博罗县| 高雄县| 汨罗市| 弥勒县| 白山市| 博野县| 古交市| 西昌市| 五家渠市| 彰武县| 阿瓦提县| 漳州市| 通州区| 青阳县| 文昌市| 江津市| 绥江县| 镇沅|