.roadhogrc.mock.js 4.26 KB
Newer Older
1 2
import mockjs from 'mockjs';
import { getRule, postRule } from './mock/rule';
3
import { getActivities, getNotice, getFakeList, postFakeList, getFakeCaptcha } from './mock/api';
4
import { getFakeChartData } from './mock/chart';
ddcat1115's avatar
ddcat1115 committed
5 6
import { getProfileBasicData } from './mock/profile';
import { getProfileAdvancedData } from './mock/profile';
7
import { getNotices } from './mock/notices';
8
import { getProvince, getCity } from './mock/geographic';
9

nikogu's avatar
nikogu committed
10 11
// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';
12

nikogu's avatar
nikogu committed
13
// 代码中会兼容本地 service mock 以及部署站点的静态数据
14 15 16
const proxy = {
  // 支持值为 Object 和 Array
  'GET /api/currentUser': {
陈帅's avatar
陈帅 committed
17 18 19 20 21 22 23 24 25 26 27
    name: 'Serati Ma',
    avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
    userid: '00000001',
    email: 'antdesign@alipay.com',
    signature: '海纳百川,有容乃大',
    title: '交互专家',
    group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
    tags: [
      {
        key: '0',
        label: '很有想法的',
28
      },
陈帅's avatar
陈帅 committed
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
      {
        key: '1',
        label: '专注设计',
      },
      {
        key: '2',
        label: '辣~',
      },
      {
        key: '3',
        label: '大长腿',
      },
      {
        key: '4',
        label: '川妹子',
      },
      {
        key: '5',
        label: '海纳百川',
      },
    ],
    notifyCount: 12,
    country: 'China',
    geographic: {
      province: {
        label: '浙江省',
        key: '330000',
      },
      city: {
        label: '杭州市',
        key: '330100',
陈帅's avatar
陈帅 committed
60
      },
61
    },
陈帅's avatar
陈帅 committed
62 63
    address: '西湖区工专路 77 号',
    phone: '0752-268888888',
64 65
  },
  // GET POST 可省略
陈帅's avatar
陈帅 committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  'GET /api/users': [
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      address: 'New York No. 1 Lake Park',
    },
    {
      key: '2',
      name: 'Jim Green',
      age: 42,
      address: 'London No. 1 Lake Park',
    },
    {
      key: '3',
      name: 'Joe Black',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
    },
  ],
86 87 88
  'GET /api/project/notice': getNotice,
  'GET /api/activities': getActivities,
  'GET /api/rule': getRule,
陈帅's avatar
陈帅 committed
89
  'POST /api/rule': postRule,
90
  'POST /api/forms': (req, res) => {
afc163's avatar
afc163 committed
91
    res.send({ message: 'Ok' });
92 93
  },
  'GET /api/tags': mockjs.mock({
陈帅's avatar
陈帅 committed
94
    'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
95 96
  }),
  'GET /api/fake_list': getFakeList,
valleykid's avatar
valleykid committed
97
  'POST /api/fake_list': postFakeList,
98
  'GET /api/fake_chart_data': getFakeChartData,
ddcat1115's avatar
ddcat1115 committed
99 100
  'GET /api/profile/basic': getProfileBasicData,
  'GET /api/profile/advanced': getProfileAdvancedData,
101
  'POST /api/login/account': (req, res) => {
afc163's avatar
afc163 committed
102
    const { password, userName, type } = req.body;
陈帅's avatar
陈帅 committed
103
    if (password === '888888' && userName === 'admin') {
ddcat1115's avatar
ddcat1115 committed
104 105 106
      res.send({
        status: 'ok',
        type,
陈帅's avatar
陈帅 committed
107
        currentAuthority: 'admin',
ddcat1115's avatar
ddcat1115 committed
108
      });
陈帅's avatar
陈帅 committed
109
      return;
ddcat1115's avatar
ddcat1115 committed
110
    }
陈帅's avatar
陈帅 committed
111
    if (password === '123456' && userName === 'user') {
ddcat1115's avatar
ddcat1115 committed
112 113 114
      res.send({
        status: 'ok',
        type,
陈帅's avatar
陈帅 committed
115
        currentAuthority: 'user',
ddcat1115's avatar
ddcat1115 committed
116
      });
陈帅's avatar
陈帅 committed
117
      return;
ddcat1115's avatar
ddcat1115 committed
118
    }
afc163's avatar
afc163 committed
119
    res.send({
ddcat1115's avatar
ddcat1115 committed
120
      status: 'error',
afc163's avatar
afc163 committed
121
      type,
陈帅's avatar
陈帅 committed
122
      currentAuthority: 'guest',
afc163's avatar
afc163 committed
123
    });
124 125
  },
  'POST /api/register': (req, res) => {
ddcat1115's avatar
ddcat1115 committed
126
    res.send({ status: 'ok', currentAuthority: 'user' });
127 128
  },
  'GET /api/notices': getNotices,
陈帅's avatar
陈帅 committed
129 130
  'GET /api/500': (req, res) => {
    res.status(500).send({
陈帅's avatar
陈帅 committed
131 132 133 134 135
      timestamp: 1513932555104,
      status: 500,
      error: 'error',
      message: 'error',
      path: '/base/category/list',
陈帅's avatar
陈帅 committed
136 137 138 139
    });
  },
  'GET /api/404': (req, res) => {
    res.status(404).send({
陈帅's avatar
陈帅 committed
140 141 142 143 144
      timestamp: 1513932643431,
      status: 404,
      error: 'Not Found',
      message: 'No message available',
      path: '/base/category/list/2121212',
陈帅's avatar
陈帅 committed
145 146 147 148
    });
  },
  'GET /api/403': (req, res) => {
    res.status(403).send({
陈帅's avatar
陈帅 committed
149 150 151 152 153
      timestamp: 1513932555104,
      status: 403,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
陈帅's avatar
陈帅 committed
154 155
    });
  },
156 157
  'GET /api/401': (req, res) => {
    res.status(401).send({
陈帅's avatar
陈帅 committed
158 159 160 161 162
      timestamp: 1513932555104,
      status: 401,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
163 164
    });
  },
陈帅's avatar
陈帅 committed
165 166
  'GET /api/geographic/province': getProvince,
  'GET /api/geographic/city/:province': getCity,
167
  'GET /api/captcha': getFakeCaptcha,
168 169
};

陈帅's avatar
陈帅 committed
170
export default (noProxy ? {} : proxy);