tachybase_todo/docs/examples/demos/demo1.tsx
Junyi 60b966f59e
Fix: plugin-file-manager (#111)
* fix: test cases

* fix env used by file manager

* default value of process.env.LOCAL_STORAGE_BASE_URL

* use workspace dependencies

* refactor some env to adapt more scenario

* fix reviewing issues

* fix env default value

* update umi config

* bugfix

* fix shared cache

Co-authored-by: chenos <chenlinxh@gmail.com>
2021-12-03 07:31:22 +08:00

69 lines
1.4 KiB
TypeScript

import { useRequest } from 'ahooks';
import { Spin } from 'antd';
import React, { useMemo } from 'react';
import { HashRouter as Router } from 'react-router-dom';
import {
createRouteSwitch,
RouteRedirectProps,
AdminLayout,
AuthLayout,
RouteSchemaRenderer,
ConfigProvider,
ClientSDK,
} from '@nocobase/client';
import { UseRequestProvider } from 'ahooks';
import { extend } from 'umi-request';
const request = extend({
prefix: process.env.API_BASE_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}`;
}
headers['X-Hostname'] = window.location.hostname;
await next();
});
const client = new ClientSDK({
request,
});
const RouteSwitch = createRouteSwitch({
components: {
AdminLayout,
AuthLayout,
RouteSchemaRenderer,
},
});
const App = () => {
const { data, loading } = useRequest('routes:getAccessible', {
formatResult: (result) => result?.data,
});
if (loading) {
return <Spin size={'large'} className={'nb-spin-center'} />;
}
return (
<div>
<Router>
<RouteSwitch routes={data} />
</Router>
</div>
);
};
export default () => {
return (
<ConfigProvider client={client}>
<App />
</ConfigProvider>
);
};