如何将fodi后端部署到cloudbase

64次阅读
没有评论

共计 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-17发表,共计3536字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)