千家信息网

如何将fodi后端部署到cloudbase

发表于:2025-02-01 作者:千家信息网编辑
千家信息网最后更新 2025年02月01日,这篇文章主要介绍了如何将fodi后端部署到cloudbase,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。上传和修改后端逻辑:用clo
千家信息网最后更新 2025年02月01日如何将fodi后端部署到cloudbase

这篇文章主要介绍了如何将fodi后端部署到cloudbase,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

上传和修改后端逻辑:

用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:

Error

Please set the refresh_token in environments
Get a refresh_token
allow javascript

如果是国际版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

                        OneManager jump page                                No link here!
If not auto jump, click the link to jump.
如果长时间未跳转,请点击上方链接继续安装。

把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可看到),则在后端面板中需要配置一条客户端网站的安全域名。

感谢你能够认真阅读完这篇文章,希望小编分享的"如何将fodi后端部署到cloudbase"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

0