armbian通过node20-alpine和mariadb部署小程序数据库

测试条件

  • 在家里有个armbian服务器

  • docker中安装有mariadb数据库和NodeJS 本地接口服务

  • 微信开发者工具 不校验合法域名 打勾 ✅

  • docker-compose内容:

    version: '3.8'

    services:
    db:
    image: mariadb:latest
    container_name: mariadb
    restart: always
    environment:
    MYSQL_ROOT_PASSWORD: 123456
    MYSQL_DATABASE: weapp_account
    volumes:
    - /bash/wxchat/data:/var/lib/mysql
    ports:
    - 3306:3306
    networks:
    - app-net

    wxchatapi:
    image: node:20.14.0-alpine
    container_name: wxchatapi
    restart: always
    working_dir: /app
    ports:
    - 3000:3000
    volumes:
    - ./api:/app
    command: sh -c "npm install && node app.js"
    depends_on:
    - db
    networks:
    - app-net

    networks:
    app-net:

第 1 步打开微信开发者工具 → 开启本地调试

  • 打开微信开发者工具→点击右上角的【三】打开详情页
  • 点击【本地设置】
  • 勾选 【不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书】

第 2 步:把小程序的接口地址改成 本地地址

打开 utils/request.js 把原来的:

const baseURL = 'https://wxchat.aaaaa.top'

改成 本地接口

const baseURL = 'http://192.168.50.86:3000'

这样小程序就会 访问你电脑本地的接口,而不是线上服务器。

第 3 步:设置在armbian服务器 nodejs

  • 修改app.js(本地接口)的如下内容:
    // 本地数据库连接(你电脑上的微信开发者工具)
    const db = mysql.createPool({
    host: '192.168.50.86', // armbian服务器的地址
    user: 'root', // 你的MySQL用户名
    password: '123456', // 你的MySQL密码
    database: 'weapp_account', // 数据库名
    waitForConnections: true,
    connectionLimit: 10
    })