magic-api 整合 git 插件详细教程

前言

magic api 是一个优秀的框架,但是备份功能对pg支持不太友好(issues/I68S9A 默认数据库使用pg且开启编辑备份,无法查看接口历史内容),magic-api作者似乎也没有兼容pg的意思。好在magic api还有一个git备份的功能,官方这方面的文档比较少,所以自己写下了这个教程。

一、生成rsa密钥

1. 运行以下命令生成 RSA 密钥:

ssh-keygen -t rsa -b 2048 -m PEM

在这里插入图片描述

2. 找到 ~/.ssh/id_rsa.pub 文件,复制其内容到 GitLab 的 SSH 密钥配置中。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3. 添加known_hosts,将输出内容配置到known_hosts中

ssh-keyscan -t rsa gitlab.com

在这里插入图片描述
在这里插入图片描述

4. 配置config

Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile C:\Users\Administrator\.ssh\id_rsa
    IdentitiesOnly yes

在这里插入图片描述

5. 配置magic-api

参考官网的完整配置,这里就贴出地址:
magic-api springboot配置
magic-api git配置

application.yml

magic-api:
  resource:
    type: git
    git:
      url: git@gitlab.com:zhiyi98/spring-magic-api.git
      branch: main
      privateKey: C:\Users\Administrator\.ssh\id_rsa
    # 本地存放路径
    location: D:/magic-api

pom.xml

<dependency>
    <groupId>org.ssssssss</groupId>
    <artifactId>magic-api-plugin-git</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

二、打开magic-api测试

启动项目
在这里插入图片描述
随便写个接口,可以看到接口的修改记录。保存看看有没有将备份内容上传到gitlab上。
在这里插入图片描述
gitlab上有提交记录说明备份成功了
在这里插入图片描述
可以看到修改时间,和接口内容做了变更
在这里插入图片描述

三、附上springboot 完整配置

magic-api:
  resource:
    type: git
    git:
      url: git@gitlab.com:zhiyi98/spring-magic-api.git
      branch: main
      privateKey: C:\Users\Administrator\.ssh\id_rsa
    # 本地存放路径
    location: D:/magic-api
  web: /magic/web # UI请求的界面以及UI服务地址
  prefix: / # 接口前缀,可以不配置
  auto-import-module: db  # 自动导入的模块
  auto-import-package: java.lang.*,java.util.* #自动导包
  allow-override: false #禁止覆盖应用接口
  sql-column-case: camel #启用驼峰命名转换
  editor-config: classpath:./magic-editor.js #编辑器配置
  support-cross-domain: true # 跨域支持,默认开启
  secret-key: 123456789 # 远程推送时的秘钥,未配置则不开启推送
  push-path: /_magic-api-sync #远程推送的路径,默认为/_magic-api-sync
  show-sql: true #配置打印SQL
  compile-cache-size: 500 #配置编译缓存容量
  persistence-response-body: true #是否持久化保存ResponseBody
  date-pattern: # 配置请求参数支持的日期格式
    - yyyy-MM-dd
    - yyyy-MM-dd HH:mm:ss
    - yyyyMMddHHmmss
    - yyyyMMdd
  response: |- #配置JSON格式,格式为magic-script中的表达式
    {
      code: code,
      message: message,
      data,
      timestamp,
      requestTime,
      executeTime,
    }
  response-code:
    success: 1 #执行成功的code值
    invalid: 0 #参数验证未通过的code值
    exception: -1 #执行出现异常的code值
  banner: true # 打印banner
  thread-pool-executor-size: 8 # async语句的线程池大小
  throw-exception: false #执行出错时是否抛出异常
  backup: #备份相关配置
    enable: true #是否启用
    max-history: -1 #备份保留天数,-1为永久保留
    table-name: magic_backup_record_v2 #使用数据库存储备份时的表名
  crud: # CRUD相关配置
    logic-delete-column: deleted #逻辑删除列
    logic-delete-value: 1 #逻辑删除值
  cache: # 缓存相关配置
    capacity: 10000 #缓存容量
    ttl: -1 # 永不过期
    enable: true # 启用缓存
  page:
    size: size # 页大小的参数名称
    page: page # 页码的参数名称
    default-page: 1 # 未传页码时的默认首页
    default-size: 10 # 未传页大小时的默认页大小
  security: # 安全配置
    username: admin # 登录用的用户名
    password: 123456 # 登录用的密码
  debug:
    timeout: 60 # 断点超时时间,默认60s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值