Blame view

old/app.py 1.73 KB
cccb7cfc   tangwang   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  from flask import Flask, jsonify
  from config import Config
  from routes.auth import auth_bp
  from routes.api import api_bp
  from routes.webhook import webhook_bp
  import logging
  
  def create_app():
      """创建Flask应用"""
      app = Flask(__name__)
      
      # 配置应用
      app.config.from_object(Config)
      
      # 配置日志
      logging.basicConfig(level=logging.INFO)
      
      # 注册蓝图
      app.register_blueprint(auth_bp)
      app.register_blueprint(api_bp)
      app.register_blueprint(webhook_bp)
      
      # 根路由
      @app.route('/')
      def index():
          return jsonify({
              'message': 'Shoplazza OAuth2.0 Backend Service',
              'version': '1.0.0',
              'endpoints': {
                  'auth': {
                      'install': '/auth/install?shop=your-shop.myshoplaza.com',
                      'callback': '/auth/shoplazza/callback',
                      'refresh_token': '/auth/refresh_token/<shop>',
                      'tokens': '/auth/tokens'
                  },
                  'api': {
                      'customers': '/api/customers/<shop>',
                      'products': '/api/products/<shop>',
                      'orders': '/api/orders/<shop>',
                      'shop_info': '/api/shop_info/<shop>'
                  },
                  'webhook': {
                      'shoplazza': '/webhook/shoplazza'
                  }
              }
          })
      
      # 健康检查端点
      @app.route('/health')
      def health():
          return jsonify({
              'status': 'healthy',
              'authorized_shops': len(Config.ACCESS_TOKENS)
          })
      
      return app
  
  if __name__ == '__main__':
      app = create_app()
      app.run(
          host='0.0.0.0',
          port=Config.PORT,
          debug=Config.DEBUG
      )