endpoint.js 881 B

1234567891011121314151617181920212223242526272829303132
  1. import request from './request';
  2. import regeneratorRuntime from '@/common/static/lib/runtime';
  3. import config from '../config';
  4. const endpoints = {
  5. getUploadToken: (data) => ({
  6. isQiniu: true,
  7. path: '/upload/getUploadToken',
  8. data,
  9. method: 'POST',
  10. }),
  11. };
  12. const getHost = (requestOptions) => {
  13. const { newUrl } = config;
  14. if (requestOptions.isQiniu) {
  15. return newUrl+"elab-marketing-file";
  16. }
  17. return newUrl+"elab-wuxi-project";
  18. };
  19. export default async (endpoint, ...options) => {
  20. if (!endpoints.hasOwnProperty(endpoint)) {
  21. console.error(`no such endpoint: ${endpoint}`);
  22. return;
  23. }
  24. const requestOptions = endpoints[endpoint].apply(null, options);
  25. requestOptions.url = getHost(requestOptions) + requestOptions.path;
  26. const response = await request(requestOptions);
  27. console.log({ url: requestOptions.url, req: requestOptions, res: response });
  28. return response;
  29. }