fix: client request undefined
This commit is contained in:
parent
31ddfbee22
commit
1cb28f0309
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user