# 将lib里边的文件加到路由中 import sys sys.path.append('./lib') from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory, Response, make_response from allFunction import manageLogin, manageActivation, manageDownload, manageUpload app = Flask(__name__) # 引入跨域访问处理模块 from flask_cors import CORS # 取消跨域访问限制,方便本地测试 注册CORS, "/*" 允许访问所有api CORS(app, resources=r'/*') # 测试用根路由 @app.route('/api/') def sayHello(): return 'Hello! Glad to serve you, please go to the official website: https://canary.lacus.site' # 登录或者注册 @app.route('/api/login', methods=["POST"]) def login(): res = manageLogin(request) return res # 激活账户 @app.route('/api/activation', methods=["POST"]) def activation(): res = manageActivation(request) return res # 更新本地数据 @app.route('/api/download', methods=["POST"]) def download(): res = manageDownload(request) return res # 更新云端数据 @app.route('/api/upload', methods=["POST"]) def upload(): res = manageUpload(request) return res # 访问拦截器转发到根路由 @app.errorhandler(404) def miss(e): return redirect('/api') if __name__ == '__main__': app.run(host="0.0.0.0", debug=True, port="80")