关于部署mall-cook,几个需要改的js文件

1.   packages\mall-cook-service\routes\upload.js

/*
 * @Description: What's this for
 * @Autor: WangYuan
 * @Date: 2021-08-17 14:28:29
 * @LastEditors: WangYuan
 * @LastEditTime: 2022-03-02 15:13:34
 */
const tools = require('../utils/tools')
const multer = require('koa-multer');
const Router = require('koa-router')
const config = require('../config')

const path = require('path')
const fs = require('fs')
const dayjs =require('dayjs')

const router = new Router()

//创建文件夹
function mkdirsSync(dirname){
  if(fs.existsSync(dirname)){
    return true;
  }else{
    if(mkdirsSync(path.dirname(dirname))){
      fs.mkdirSync(dirname)
      return true
    }
  }
}


//文件上传
var storage = multer.diskStorage({
  //文件保存路径
  destination: function (req, file, cb) {
    //appjs中koa-static配置目录为public,因此上传目录放public;也可以配置koa-static
    const filePath = `${path.resolve('./public')}/img/${dayjs(Date.now()).format('YYYYMMDD')}`
      //递归创建多级
      if(mkdirsSync(filePath)){
        cb(null, filePath)
      }
       
  },
  //修改文件名称
  filename: function (req, file, cb) {
    var fileFormat = (file.originalname).split(".");
    cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
  }
})
//加载配置
var upload = multer({ storage: storage });


//路由
router.post('/upload', upload.single('file'), async (ctx, next) => {
  ctx.body = {
      data: `${config.serviceApi}/img/${dayjs(Date.now()).format('YYYYMMDD')}/${ctx.req.file.filename}`,
      errorCode: "00000",
      message: "请求成功",
  }
  ctx.status = 200
})

module.exports = router

2. packages\mall-cook-platform\vue.config.js

devServer: {
    port: '8081', // 设置端口号
    proxy: {
        '/api': {
          target: 'http://localhost:3000', //API服务器的地址
          ws: true, //代理websockets
          changeOrigin: true, // 是否跨域,虚拟的站点需要更管origin
          pathRewrite: {
            '^/api': '',
          }
        }
    },
  }

3. packages\mall-cook-platform\src\config\global.js

/*
 * @Description: What's this for
 * @Autor: WangYuan
 * @Date: 2022-02-11 10:08:57
 * @LastEditors: WangYuan
 * @LastEditTime: 2022-11-02 09:10:53
 */
export default {
  baseApi: 'http://localhost:3000/',  // 后端接口地址
  viewUrl: 'http://localhost:8080/#/'          // iframe嵌套的H5地址,本地开发可改为本地启动的H5地址
  // baseApi: 'http://www.sunmao-design.top/mall-cook/api/', // 后端接口地址
  // viewUrl: 'http://139.196.223.93:4001/#/', // iframe嵌套的H5地址,本地开发可改为本地启动的H5地址
}

4. packages\mall-cook-template\src\utils\request.js

const baseUrl = 'http://localhost:3000'

5. packages\mall-cook-service\config.js

/*
 * @Description: 配置信息
 * @Autor: WangYuan
 * @Date: 2022-02-10 19:20:33
 * @LastEditors: WangYuan
 * @LastEditTime: 2022-11-02 10:35:50
 */
config = {
  appid: 'xxx', // 小程序appId
  secret: 'xxx', // 小程序secret
  serviceApi: 'http://localhost:3000', // 服务器地址
  mongodbUrl: 'mongodb://localhost:27017', // mongodb数据库地址 格式:mongodb://username:password@host:port/name
  jwtSecret: 'secret'
}

module.exports = config

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值