Commit 6a7aa227 authored by chenos's avatar chenos
Browse files

feat: improve code

parent 019d182a
Showing with 27 additions and 3 deletions
+27 -3
......@@ -41,7 +41,6 @@ const plugins = [
'@nocobase/plugin-collection-manager',
'@nocobase/plugin-ui-schema-storage',
'@nocobase/plugin-ui-routes-storage',
'@nocobase/plugin-client',
'@nocobase/plugin-file-manager',
'@nocobase/plugin-system-settings',
'@nocobase/plugin-users',
......@@ -53,6 +52,10 @@ for (const plugin of plugins) {
api.plugin(require(plugin).default);
}
api.plugin(require('@nocobase/plugin-client').default, {
dist: resolve(__dirname, '../../app/dist'),
});
if (process.argv.length < 3) {
// @ts-ignore
process.argv.push('start', '--port', process.env.API_PORT || 12302);
......
......@@ -13,6 +13,7 @@ const umiConfig = getUmiConfig();
export default defineConfig({
define: {
'process.env.NOCOBASE_ENV': process.env.NOCOBASE_ENV,
...umiConfig.define,
},
// only proxy when using `umi dev`
......
......@@ -35,6 +35,8 @@ import { I18nextProvider } from 'react-i18next';
import { Link, NavLink } from 'react-router-dom';
import apiClient from './apiClient';
console.log = (...args) => null;
apiClient.axios.interceptors.response.use(
(response) => response,
(error) => {
......
import debug from 'debug';
import './global.less';
debug.log = console.log.bind(console);
export * from './acl';
export * from './antd-config-provider';
......
import { skip } from '@nocobase/acl';
import { Plugin } from '@nocobase/server';
import send from 'koa-send';
import serve from 'koa-static';
import { resolve } from 'path';
export class ClientPlugin extends Plugin {
async beforeLoad() {
......@@ -36,6 +39,23 @@ export class ClientPlugin extends Plugin {
},
},
});
let root = this.options.dist;
if (root && !root.startsWith('/')) {
root = resolve(process.cwd(), root);
}
this.app.middleware.unshift(async (ctx, next) => {
if (process.env.NOCOBASE_ENV === 'production') {
return next();
}
if (!root) {
return next();
}
await serve(root)(ctx, next);
// console.log('koa-send', root, ctx.status);
if (ctx.status == 404) {
return send(ctx, 'index.html', { root });
}
});
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment