fix: client request undefined

This commit is contained in:
chenos 2021-09-30 09:45:03 +08:00
parent 31ddfbee22
commit 1cb28f0309
2 changed files with 23 additions and 3 deletions

View File

@ -3,8 +3,28 @@ import { UseRequestProvider } from 'ahooks';
import { ISchema } from '../schemas';
import { Schema, useField } from '@formily/react';
import { Resource } from '../resource';
import { ClientSDK } from '../ClientSDK';
import { extend } from 'umi-request';
const ClientContext = createContext<any>(null);
export const request = extend({
prefix: process.env.API_URL,
timeout: 30000,
});
request.use(async (ctx, next) => {
const { headers } = ctx.req.options as any;
const token = localStorage.getItem('NOCOBASE_TOKEN');
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
await next();
});
const client = new ClientSDK({
request,
});
const ClientContext = createContext<any>(client);
export function ClientProvider(props) {
const { client } = props;

View File

@ -1,5 +1,5 @@
import { RequestMethod } from 'umi-request';
import { request } from './schemas';
import { request as req } from './schemas';
export interface ResourceOptions {
resourceName: string;
@ -37,7 +37,7 @@ export class Resource {
} else {
this.options = options;
}
this.request = request || request;
this.request = request || req;
}
sort(options) {