0.0.2 • Published 1 year ago

encrypt-url v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

encrypt-url

安装

bib-frontend/apps内项目

执行以下命令:

pnpm add encrypt-url --filter <workspace>

如:

pnpm add encrypt-url --filter homepage

或者package.json直接添加依赖

"encrypt-url": "workspace:\*",

其他项目

npm install encrypt-url

使用(默认使用axios)

nuxt项目

plugins/request.js

import { encryptUrlInterceptor } from 'encrypt-url'

export default function ({ $axios, $winstonLog, store, redirect, app }) {
  // 直接添加
  $axios.onRequest(encryptUrlInterceptor)

  // 或者
  $axios.onRequest(config => {
    ......
    if (
      (process.env.NODE_ENV === 'production' &&
        ['prod', 'uat'].includes(process.env.ENV))
    ) {
      encryptUrlInterceptor(config)
    }

    return config
  })
}

普通项目

import axios from 'axios';
import { encryptUrlInterceptor } from 'encrypt-url'

if (process.env.NODE_ENV === 'production' && ['prod', 'uat'].includes(process.env.ENV))) {
  axios.interceptors.request.use(encryptUrlInterceptor)
}

配置

默认对所有url请求开启 url加密

encryptUrl

encryptUrl: false 可针对某个接口 关闭url加密

test2(params = {}) {
  return request({
    url: '/test2/url,
    method: 'post',
    data: params,
    encryptUrl: false
  })
}