feat: improve code
This commit is contained in:
parent
73145b56ad
commit
29d386a63d
@ -7,12 +7,13 @@ export default defineConfig({
|
||||
hash: true,
|
||||
define: {
|
||||
'process.env.API_URL': process.env.API_URL,
|
||||
'process.env.API_HOSTNAME': process.env.API_HOSTNAME,
|
||||
},
|
||||
proxy: {
|
||||
'/api': {
|
||||
'target': `http://localhost:${process.env.API_PORT}/`,
|
||||
'changeOrigin': true,
|
||||
'pathRewrite': { '^/api' : '/api' },
|
||||
'pathRewrite': { '^/api/': '/api/' },
|
||||
},
|
||||
},
|
||||
// mfsu: {},
|
||||
|
@ -12,12 +12,13 @@ export default defineConfig({
|
||||
},
|
||||
define: {
|
||||
'process.env.API_URL': process.env.API_URL,
|
||||
'process.env.API_PORT': process.env.API_PORT,
|
||||
},
|
||||
proxy: {
|
||||
'/api': {
|
||||
'target': `http://localhost:${process.env.API_PORT}/`,
|
||||
'changeOrigin': true,
|
||||
'pathRewrite': { '^/api' : '/api' },
|
||||
'pathRewrite': { '^/api': '/api' },
|
||||
},
|
||||
},
|
||||
routes: [
|
||||
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"watch": ["src/api/", ".env"],
|
||||
"ext": "ts",
|
||||
"exec": "cross-env TS_NODE_PROJECT=\"tsconfig.api.json\" ts-node -r dotenv/config ./src/api/index.ts"
|
||||
}
|
@ -29,6 +29,7 @@
|
||||
"@nocobase/plugin-action-logs": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-automations": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-china-region": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-client": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-collections": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-file-manager": "^0.4.0-alpha.7",
|
||||
"@nocobase/plugin-pages": "^0.4.0-alpha.7",
|
||||
@ -39,7 +40,6 @@
|
||||
"@nocobase/plugin-multi-apps": "^0.4.0-alpha.7",
|
||||
"@nocobase/server": "^0.4.0-alpha.7",
|
||||
"@umijs/preset-react": "1.x",
|
||||
"koa-mount": "^4.0.0",
|
||||
"umi": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -52,7 +52,6 @@
|
||||
"prettier": "^2.2.0",
|
||||
"react": "17.x",
|
||||
"react-dom": "17.x",
|
||||
"ts-node": "^10.2.1",
|
||||
"ts-node-dev": "^1.1.8",
|
||||
"yorkie": "^2.0.0"
|
||||
}
|
||||
|
@ -55,9 +55,16 @@ const plugins = [
|
||||
];
|
||||
|
||||
for (const plugin of plugins) {
|
||||
api.plugin(require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default);
|
||||
api.plugin(
|
||||
require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default,
|
||||
);
|
||||
}
|
||||
|
||||
api.plugin(
|
||||
require(`@nocobase/plugin-client/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default, {
|
||||
dist: path.resolve(process.cwd(), './dist'),
|
||||
});
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
// @ts-ignore
|
||||
process.argv.push('start', '--port', process.env.API_PORT);
|
||||
|
@ -13,8 +13,10 @@ import {
|
||||
} from '@nocobase/client';
|
||||
import { extend } from 'umi-request';
|
||||
|
||||
console.log(`${location.protocol}//${location.hostname}:${process.env.API_PORT}/api/`);
|
||||
|
||||
const request = extend({
|
||||
prefix: process.env.API_URL,
|
||||
prefix: `${location.protocol}//${location.hostname}:${process.env.API_PORT}/api/`,
|
||||
timeout: 30000,
|
||||
});
|
||||
|
||||
|
@ -1,9 +1,24 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./lib/apis"
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"module": "commonjs",
|
||||
"target": "ES6",
|
||||
"allowJs": false,
|
||||
"noUnusedLocals": false,
|
||||
"removeComments": true,
|
||||
"preserveConstEnums": true,
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"experimentalDecorators": true,
|
||||
"downlevelIteration": true,
|
||||
"baseUrl": ".",
|
||||
"outDir": "./lib/apis",
|
||||
"paths": {
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/apis",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ request.use(async (ctx, next) => {
|
||||
const token = localStorage.getItem('NOCOBASE_TOKEN');
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
headers['X-Hostname'] = process.env.API_HOSTNAME;
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
@ -8,7 +8,8 @@
|
||||
"@nocobase/resourcer": "^0.4.0-alpha.7",
|
||||
"@nocobase/server": "^0.4.0-alpha.7",
|
||||
"deepmerge": "^4.2.2",
|
||||
"flat-to-nested": "^1.1.1"
|
||||
"flat-to-nested": "^1.1.1",
|
||||
"koa-compress": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nocobase/actions": "^0.4.0-alpha.7"
|
||||
|
@ -0,0 +1,38 @@
|
||||
import path from 'path';
|
||||
import send from 'koa-send';
|
||||
import serve from 'koa-static';
|
||||
import { PluginOptions } from '@nocobase/server';
|
||||
import compress from 'koa-compress';
|
||||
|
||||
export default {
|
||||
name: 'client',
|
||||
async load() {
|
||||
let root = this.options.dist;
|
||||
if (root && !root.startsWith('/')) {
|
||||
root = path.resolve(process.cwd(), root);
|
||||
}
|
||||
this.app.use(compress({
|
||||
// filter (content_type) {
|
||||
// return /text/i.test(content_type)
|
||||
// },
|
||||
threshold: 20480,
|
||||
// gzip: {
|
||||
// flush: require('zlib').constants.Z_SYNC_FLUSH
|
||||
// },
|
||||
// deflate: {
|
||||
// flush: require('zlib').constants.Z_SYNC_FLUSH,
|
||||
// },
|
||||
// br: false // disable brotli
|
||||
}));
|
||||
this.app.middleware.unshift(async (ctx, 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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
} as PluginOptions;
|
@ -29,7 +29,7 @@ INSERT INTO "ui_schemas" ("key", "name", "title", "type", "x-component", "option
|
||||
('xe5j6tk6y52', NULL, '名称', 'string', 'Input', '{"x-decorator":"FormItem","x-designable-bar":"Input.DesignableBar"}', '0', 11, '2021-09-02 22:27:03.747+00', '2021-09-02 22:27:03.747+00', NULL),
|
||||
('exjytl34657', NULL, '分类', 'array', 'Select', '{"x-component-props":{"mode":"multiple"},"x-decorator":"FormItem","x-designable-bar":"Select.DesignableBar","enum":[{"value":"6t7ymkea93i","label":"家用电器","color":"red"},{"value":"qfw5lm2ltq1","label":"日用品","color":"magenta"},{"value":"7y53n84vad6","label":"蔬菜水果","color":"orange"},{"value":"mbhrlnto7c7","label":"儿童玩具","color":"green"},{"value":"xaf8vqqc37w","label":"药品","color":"blue"},{"value":"1hqareezm1g","label":"家具","color":"purple"}]}', '0', 12, '2021-09-02 22:27:03.769+00', '2021-09-02 22:27:03.769+00', NULL),
|
||||
('4blpztuxkha', NULL, '图片', 'array', 'Upload.Attachment', '{"x-decorator":"FormItem","x-designable-bar":"Upload.DesignableBar","x-component-props":{"multiple":true}}', '0', 13, '2021-09-02 22:28:32.783+00', '2021-09-02 22:28:32.783+00', NULL),
|
||||
('4an73nd4bxh', NULL, '产地', 'array', 'Cascader', '{"x-component-props":{"changeOnSelectLast":false,"loadData":"{{ ChinaRegion.loadData }}","labelInValue":true,"maxLevel":3,"fieldNames":{"label":"name","value":"code","children":"children"}},"x-reactions":["{{ChinaRegion.useFieldValue}}","{{useAsyncDataSource(ChinaRegion.loadDataSource)}}"],"x-decorator":"FormItem","x-designable-bar":"Cascader.DesignableBar"}', '0', 14, '2021-09-02 22:28:32.807+00', '2021-09-02 22:28:32.807+00', NULL),
|
||||
('4an73nd4bxh', NULL, '产地', 'array', 'Cascader', '{"x-component-props":{"changeOnSelectLast":false,"loadData":"{{ ChinaRegion.loadData() }}","labelInValue":true,"maxLevel":3,"fieldNames":{"label":"name","value":"code","children":"children"}},"x-reactions":["{{ChinaRegion.useFieldValue}}","{{useAsyncDataSource(ChinaRegion.loadDataSource())}}"],"x-decorator":"FormItem","x-designable-bar":"Cascader.DesignableBar"}', '0', 14, '2021-09-02 22:28:32.807+00', '2021-09-02 22:28:32.807+00', NULL),
|
||||
('e5t9w7t3rxu', NULL, '价格', 'number', 'InputNumber', '{"x-component-props":{"stringMode":true,"step":"0.01"},"x-decorator":"FormItem","x-designable-bar":"InputNumber.DesignableBar"}', '0', 15, '2021-09-02 22:28:32.824+00', '2021-09-02 22:28:32.824+00', NULL),
|
||||
('hej1gpzthf3', NULL, '商品描述', 'string', 'Input.TextArea', '{"x-decorator":"FormItem","x-designable-bar":"Input.DesignableBar"}', '0', 16, '2021-09-02 22:28:32.843+00', '2021-09-02 22:28:32.843+00', NULL),
|
||||
('zh4zpw15qpz', 'rxfyczia6um', NULL, 'void', 'Grid.Row', '{"version":"2.0"}', '0', 1, '2021-09-03 07:17:56.728+00', '2021-09-03 07:17:56.728+00', 'y9qcc6ds2j3'),
|
||||
@ -332,7 +332,7 @@ INSERT INTO "ui_schemas" ("key", "name", "title", "type", "x-component", "option
|
||||
('2h9pf1b6olk', '9o4lf7kfp0o', NULL, 'void', 'Form.Field', '{"_isJSONSchemaObject":true,"version":"2.0","x-decorator":"Form.Field.Item","x-designable-bar":"Form.Field.DesignableBar","x-component-props":{"fieldName":"f_bysgds7j36p"}}', '0', 1, '2021-09-12 01:14:19.975+00', '2021-09-12 01:15:08.468+00', 'a3lfj4ufg57'),
|
||||
('a3lfj4ufg57', '8l8m8wufce1', NULL, 'void', 'Grid.Col', '{"version":"2.0"}', '0', 0, '2021-09-12 01:15:08.455+00', '2021-09-12 01:15:08.483+00', 'hluydy0pi2o'),
|
||||
('zncs2fmi3md', NULL, '会员等级', 'string', 'Select', '{"x-decorator":"FormItem","x-designable-bar":"Select.DesignableBar","enum":[{"value":"z7wq1mkwmmx","label":"拂晓会员","color":"blue"},{"value":"plcxasw2xrs","label":"日暮会员","color":"orange"},{"value":"e3fb46gnarj","label":"青柠会员","color":"lime"},{"value":"h5cxo6g48lj","label":" 酱紫会员","color":"purple"}]}', '0', 49, '2021-09-12 01:17:01.049+00', '2021-09-12 01:17:01.049+00', NULL),
|
||||
('o21p57oi4ci', NULL, '地址', 'array', 'Cascader', '{"x-component-props":{"changeOnSelectLast":false,"loadData":"{{ ChinaRegion.loadData }}","labelInValue":true,"maxLevel":3,"fieldNames":{"label":"name","value":"code","children":"children"}},"x-reactions":["{{ChinaRegion.useFieldValue}}","{{useAsyncDataSource(ChinaRegion.loadDataSource)}}"],"x-decorator":"FormItem","x-designable-bar":"Cascader.DesignableBar"}', '0', 50, '2021-09-12 01:17:01.065+00', '2021-09-12 01:17:01.065+00', NULL),
|
||||
('o21p57oi4ci', NULL, '地址', 'array', 'Cascader', '{"x-component-props":{"changeOnSelectLast":false,"loadData":"{{ ChinaRegion.loadData() }}","labelInValue":true,"maxLevel":3,"fieldNames":{"label":"name","value":"code","children":"children"}},"x-reactions":["{{ChinaRegion.useFieldValue}}","{{useAsyncDataSource(ChinaRegion.loadDataSource())}}"],"x-decorator":"FormItem","x-designable-bar":"Cascader.DesignableBar"}', '0', 50, '2021-09-12 01:17:01.065+00', '2021-09-12 01:17:01.065+00', NULL),
|
||||
('y9pc4sua6q7', '0wicv1in4co', NULL, 'void', 'Grid.Row', '{"version":"2.0","_isJSONSchemaObject":true}', '0', 3, '2021-09-23 02:53:11.395+00', '2021-09-23 02:53:16.615+00', 'k50qsygrdju'),
|
||||
('cexqu9aljyo', 'viqzudzapsd', NULL, 'void', 'Form.Field', '{"_isJSONSchemaObject":true,"version":"2.0","x-decorator":"Form.Field.Item","x-designable-bar":"Form.Field.DesignableBar","x-component-props":{"fieldName":"f_vgw4f62h16e"}}', '0', 1, '2021-09-12 01:21:29.499+00', '2021-09-12 01:21:29.499+00', 'anwph5e5kub'),
|
||||
('atinc1dlozk', 'gtwsrd24pwu', NULL, 'void', 'Grid.Col', '{"_isJSONSchemaObject":true,"version":"2.0"}', '0', 1, '2021-09-12 01:17:30.204+00', '2021-09-12 01:17:30.204+00', NULL),
|
||||
|
@ -27,3 +27,4 @@ INSERT INTO "attachments" ("id", "title", "filename", "extname", "size", "mimety
|
||||
(26, 'kaffeerad-1543158_1280', '8b94dd8cbecdbbd03e4c2fcfbd1067e7.jpg', '.jpg', NULL, 'image/jpeg', '', '{}', 'https://nocobase.oss-cn-beijing.aliyuncs.com/8b94dd8cbecdbbd03e4c2fcfbd1067e7.jpg', '2021-09-12 07:47:39.63+00', '2021-09-12 07:47:39.63+00', NULL, 1, 2),
|
||||
(28, 'apple-1609693_1280', '31b7dee511a8d6364fee18411763c188.jpg', '.jpg', NULL, 'image/jpeg', '', '{}', 'https://nocobase.oss-cn-beijing.aliyuncs.com/31b7dee511a8d6364fee18411763c188.jpg', '2021-09-12 07:48:41.367+00', '2021-09-12 07:48:41.367+00', NULL, 1, 2),
|
||||
(29, 'cappuccino-1609932_1280', '8f480c4f1bd3d292ef78fb6847669e51.jpg', '.jpg', NULL, 'image/jpeg', '', '{}', 'https://nocobase.oss-cn-beijing.aliyuncs.com/8f480c4f1bd3d292ef78fb6847669e51.jpg', '2021-09-12 07:48:41.372+00', '2021-09-12 07:48:41.372+00', NULL, 1, 2);
|
||||
SELECT setval('attachments_id_seq', (SELECT MAX(id) FROM "attachments"), true);
|
||||
|
@ -5,3 +5,4 @@ INSERT INTO "t_2uhu4szs1kq" ("id", "created_at", "updated_at", "sort", "created_
|
||||
(4, '2021-09-12 08:02:37.852+00', '2021-09-18 07:50:34.039+00', 72, 1, 1, '包派极都火题折究条', '2021-10-08 00:00:00+00', 'zfowtv6fnel', '利本毛所线表体定质花,则根物大教斯经前,飞能D发科程W目。 阶直少看员片飞飞今西取亲本就条,持层品平米今ON孤你七2。 花离定可除展通向业很,斗术真节西严特矿,导养-N群长置便。 深规马细三强低按段,事作般习就代它,完技O布D枝快。 便报动斗改克离为具影研立特,养命规么才设步局方总较共张,时什Q肃声的者起开出话。'),
|
||||
(6, '2021-09-17 01:35:18.379+00', '2021-09-18 07:50:34.039+00', 73, 1, 1, '达到顶峰五十五分', '2021-09-17 00:00:00+00', 'zfowtv6fnel', NULL),
|
||||
(3, '2021-09-12 08:02:20.501+00', '2021-09-18 07:50:34.042+00', 68, 1, 1, '往你周观青整积元路公', '2021-09-24 00:00:00+00', 'lebkfnj3d9i', '利本毛所线表体定质花,则根物大教斯经前,飞能D发科程W目。 阶直少看员片飞飞今西取亲本就条,持层品平米今ON孤你七2。 花离定可除展通向业很,斗术真节西严特矿,导养-N群长置便。 深规马细三强低按段,事作般习就代它,完技O布D枝快。 便报动斗改克离为具影研立特,养命规么才设步局方总较共张,时什Q肃声的者起开出话。');
|
||||
SELECT setval('t_2uhu4szs1kq_id_seq', (SELECT MAX(id) FROM "t_2uhu4szs1kq"), true);
|
||||
|
@ -17,4 +17,5 @@ INSERT INTO "t_fsveob6p269" ("id", "created_at", "updated_at", "sort", "created_
|
||||
少给学采议备料元民切,则建通加的志始资但线,些火医花史贡凝好。 易体报说着导收因派解,导亲动和人头之适,引都B按张观不适。 习想带证利识平率,不眼社且几质种,已U集杆X总。 及酸心知此劳记手,争小斗Z化传。 力例适支现流解斗,从经元行是南总,月辰走化习-。', 'e3fb46gnarj'),
|
||||
(6, '2021-09-12 07:43:57.617+00', '2021-09-12 08:28:50.544+00', 6, 1, 1, '宓中仕', '13527645198', 'khan8z430yx', '1999-02-26 00:00:00+00', '压界点小名理它车机两得,原查去证行村太孟道。求真强记织管装总论形感增委越,术市点便定肃容红个而写。代往门张照布活,期头劳量人,导8新建给。造装话和很片算只类论所,全变容时过地传达,术族刷车进变了邮盯。 在给情她积音新问整史图火验往,受王多式儿花6集听壳是呆。越县管积小与权内有红压,往你周观青整积元路公,包派极都火题折究条。
|
||||
|
||||
张斯些况于非按并音习又极别解切参,气斗也新越几励小集及询报吧。整展研号公清文例资品会头,厂斗志照部都越何事车前,斯队两将断极S点其会。方去即白林两团规,度关这步明管王至,但低承我质建求。 组了间族你那记的格压把,走张它然无便同儿把意,七土两叫询呜没报时。她引广书率出主且金,来万须采确部还活件,较M来霸豆板枝。政个值满物种被,共据运本很极然满,须E事眼目外。器约精机王传马,立目证权适色总,公屈过史类刺。体回每在或机发己极即,指办置们选会习十己,连难4持包厕知柜。 速还提红达知器金积外委下', 'z7wq1mkwmmx');
|
||||
张斯些况于非按并音习又极别解切参,气斗也新越几励小集及询报吧。整展研号公清文例资品会头,厂斗志照部都越何事车前,斯队两将断极S点其会。方去即白林两团规,度关这步明管王至,但低承我质建求。 组了间族你那记的格压把,走张它然无便同儿把意,七土两叫询呜没报时。她引广书率出主且金,来万须采确部还活件,较M来霸豆板枝。政个值满物种被,共据运本很极然满,须E事眼目外。器约精机王传马,立目证权适色总,公屈过史类刺。体回每在或机发己极即,指办置们选会习十己,连难4持包厕知柜。 速还提红达知器金积外委下', 'z7wq1mkwmmx');
|
||||
SELECT setval('t_fsveob6p269_id_seq', (SELECT MAX(id) FROM "t_fsveob6p269"), true);
|
||||
|
@ -15,3 +15,4 @@ INSERT INTO "t_geso7fru7a9" ("id", "created_at", "updated_at", "sort", "created_
|
||||
(14, '2021-09-14 02:06:10.875+00', '2021-09-14 02:06:10.875+00', 14, 1, 1, '2021-09-07 10:06:06+00', 'x4qnavatfai', '751834123537'),
|
||||
(15, '2021-09-14 02:06:29.102+00', '2021-09-14 02:06:29.102+00', 15, 1, 1, '2021-09-25 10:06:18+00', 'x4qnavatfai', '751834123538'),
|
||||
(16, '2021-09-14 02:06:45.054+00', '2021-09-14 02:06:45.054+00', 16, 1, 1, '2021-09-09 10:06:41+00', 'i2xjqmnwrsu', '751834123539');
|
||||
SELECT setval('t_geso7fru7a9_id_seq', (SELECT MAX(id) FROM "t_geso7fru7a9"), true);
|
||||
|
@ -4,6 +4,7 @@ import { Model } from '@nocobase/database';
|
||||
import { readFileSync } from 'fs';
|
||||
import glob from 'glob';
|
||||
import path from 'path';
|
||||
import compose from 'koa-compose';
|
||||
|
||||
function getInitSqls() {
|
||||
const part1 = [];
|
||||
@ -41,7 +42,7 @@ function createApp(opts) {
|
||||
acquire: 60000,
|
||||
idle: 10000,
|
||||
},
|
||||
// logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
|
||||
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
|
||||
define: {},
|
||||
sync: {
|
||||
force: false,
|
||||
@ -79,6 +80,8 @@ function createApp(opts) {
|
||||
'@nocobase/plugin-china-region',
|
||||
];
|
||||
|
||||
// console.log('process.cwd()', process.cwd())
|
||||
|
||||
for (const plugin of plugins) {
|
||||
app.plugin(
|
||||
require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`)
|
||||
@ -86,9 +89,17 @@ function createApp(opts) {
|
||||
);
|
||||
}
|
||||
|
||||
app.plugin(
|
||||
require(`@nocobase/plugin-client/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default, {
|
||||
dist: path.resolve(process.cwd(), './dist'),
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
// import send from 'koa-send';
|
||||
// import serve from 'koa-static';
|
||||
|
||||
function multiApps({ getAppName }) {
|
||||
return async function (ctx: Koa.Context, next) {
|
||||
const appName = getAppName(ctx);
|
||||
@ -110,6 +121,7 @@ function multiApps({ getAppName }) {
|
||||
name: appName,
|
||||
});
|
||||
await app.load();
|
||||
await app.emitAsync('beforeStart');
|
||||
apps.set(appName, app);
|
||||
}
|
||||
|
||||
@ -129,7 +141,7 @@ function multiApps({ getAppName }) {
|
||||
const index = app.middleware.indexOf(bodyParser);
|
||||
app.middleware.splice(index, 1);
|
||||
console.log('..........................end........................');
|
||||
// await next();
|
||||
await next();
|
||||
};
|
||||
}
|
||||
|
||||
@ -184,7 +196,8 @@ export default {
|
||||
});
|
||||
this.app.middleware.unshift(multiApps({
|
||||
getAppName(ctx) {
|
||||
const hostname = ctx.get('X-Hostname');
|
||||
console.log('ctx.hostname', ctx.hostname);
|
||||
const hostname = ctx.get('X-Hostname') || ctx.hostname;
|
||||
if (!hostname) {
|
||||
return;
|
||||
}
|
||||
@ -192,7 +205,6 @@ export default {
|
||||
if (keys.length < 4) {
|
||||
return;
|
||||
}
|
||||
console.log('ctx.hostname', ctx.get('X-Hostname'));
|
||||
return keys.shift();
|
||||
},
|
||||
}));
|
||||
|
13
packages/plugin-multi-apps/src/test.ts
Normal file
13
packages/plugin-multi-apps/src/test.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import glob from 'glob';
|
||||
import path from 'path';
|
||||
|
||||
function sql() {
|
||||
const arr = [];
|
||||
const files = glob.sync(path.resolve(__dirname, './db/*.sql'));
|
||||
for (const file of files) {
|
||||
const sql = readFileSync(file).toString();
|
||||
arr.push(sql);
|
||||
}
|
||||
return arr;
|
||||
}
|
@ -5,9 +5,6 @@ describe('ui_schemas', () => {
|
||||
let api: MockServer;
|
||||
beforeEach(async () => {
|
||||
api = mockServer();
|
||||
registerActions(api);
|
||||
api.registerPlugin('ui-schema', require('../server').default);
|
||||
await api.loadPlugins();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
@ -46,9 +46,8 @@ interface ActionsOptions {
|
||||
|
||||
export class Application<
|
||||
StateT = DefaultState,
|
||||
ContextT = DefaultContext
|
||||
> extends Koa {
|
||||
|
||||
ContextT = DefaultContext,
|
||||
> extends Koa {
|
||||
public readonly db: Database;
|
||||
|
||||
public readonly resourcer: Resourcer;
|
||||
@ -109,11 +108,11 @@ export class Application<
|
||||
await this.db.sync(
|
||||
force
|
||||
? {
|
||||
force: true,
|
||||
alter: {
|
||||
drop: true,
|
||||
},
|
||||
}
|
||||
force: true,
|
||||
alter: {
|
||||
drop: true,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
);
|
||||
await this.destroy();
|
||||
@ -171,9 +170,9 @@ export class Application<
|
||||
return this.cli.command(nameAndArgs, opts);
|
||||
}
|
||||
|
||||
plugin(options?: PluginType | PluginOptions): Plugin {
|
||||
plugin(options?: PluginType | PluginOptions, ext?: PluginOptions): Plugin {
|
||||
if (typeof options === 'string') {
|
||||
return this.plugin(require(options).default);
|
||||
return this.plugin(require(options).default, ext);
|
||||
}
|
||||
let instance: Plugin;
|
||||
if (typeof options === 'function') {
|
||||
@ -181,6 +180,7 @@ export class Application<
|
||||
// @ts-ignore
|
||||
instance = new options({
|
||||
name: options.name,
|
||||
...ext,
|
||||
app: this,
|
||||
});
|
||||
if (!(instance instanceof Plugin)) {
|
||||
@ -190,6 +190,7 @@ export class Application<
|
||||
// console.log(err);
|
||||
instance = new Plugin({
|
||||
name: options.name,
|
||||
...ext,
|
||||
// @ts-ignore
|
||||
load: options,
|
||||
app: this,
|
||||
@ -200,6 +201,7 @@ export class Application<
|
||||
instance = new plugin({
|
||||
name: options.plugin ? plugin.name : undefined,
|
||||
...options,
|
||||
...ext,
|
||||
app: this,
|
||||
});
|
||||
}
|
||||
|
94
yarn.lock
94
yarn.lock
@ -1745,18 +1745,6 @@
|
||||
exec-sh "^0.3.2"
|
||||
minimist "^1.2.0"
|
||||
|
||||
"@cspotcode/source-map-consumer@0.8.0":
|
||||
version "0.8.0"
|
||||
resolved "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
|
||||
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==
|
||||
|
||||
"@cspotcode/source-map-support@0.6.1":
|
||||
version "0.6.1"
|
||||
resolved "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.6.1.tgz#118511f316e2e87ee4294761868e254d3da47960"
|
||||
integrity sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg==
|
||||
dependencies:
|
||||
"@cspotcode/source-map-consumer" "0.8.0"
|
||||
|
||||
"@csstools/convert-colors@^1.4.0":
|
||||
version "1.4.0"
|
||||
resolved "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
|
||||
@ -3629,26 +3617,6 @@
|
||||
resolved "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
|
||||
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
|
||||
|
||||
"@tsconfig/node10@^1.0.7":
|
||||
version "1.0.8"
|
||||
resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
|
||||
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==
|
||||
|
||||
"@tsconfig/node12@^1.0.7":
|
||||
version "1.0.9"
|
||||
resolved "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
|
||||
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==
|
||||
|
||||
"@tsconfig/node14@^1.0.0":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
|
||||
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==
|
||||
|
||||
"@tsconfig/node16@^1.0.2":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
|
||||
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
|
||||
|
||||
"@types/accepts@*":
|
||||
version "1.3.5"
|
||||
resolved "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz#c34bec115cfc746e04fe5a059df4ce7e7b391575"
|
||||
@ -4744,11 +4712,6 @@ acorn-walk@^7.1.1:
|
||||
resolved "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc"
|
||||
integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==
|
||||
|
||||
acorn-walk@^8.1.1:
|
||||
version "8.1.1"
|
||||
resolved "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz#3ddab7f84e4a7e2313f6c414c5b7dac85f4e3ebc"
|
||||
integrity sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==
|
||||
|
||||
acorn@5.X, acorn@^5.0.3, acorn@^5.5.3:
|
||||
version "5.7.4"
|
||||
resolved "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e"
|
||||
@ -4764,7 +4727,7 @@ acorn@^7.1.1, acorn@^7.4.0:
|
||||
resolved "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
|
||||
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==
|
||||
|
||||
acorn@^8.2.4, acorn@^8.4.1:
|
||||
acorn@^8.2.4:
|
||||
version "8.4.1"
|
||||
resolved "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c"
|
||||
integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==
|
||||
@ -6049,7 +6012,7 @@ byte-size@^5.0.1:
|
||||
resolved "https://registry.npmjs.org/byte-size/-/byte-size-5.0.1.tgz#4b651039a5ecd96767e71a3d7ed380e48bed4191"
|
||||
integrity sha512-/XuKeqWocKsYa/cBY1YbSJSWWqTi4cFgr9S6OyM7PBaPbr9zvNGwWP33vt0uqGhwDdN+y3yhbXVILEUpnwEWGw==
|
||||
|
||||
bytes@3.1.0:
|
||||
bytes@3.1.0, bytes@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
|
||||
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
|
||||
@ -6757,6 +6720,13 @@ component-indexof@0.0.3:
|
||||
resolved "https://registry.npmjs.org/component-indexof/-/component-indexof-0.0.3.tgz#11d091312239eb8f32c8f25ae9cb002ffe8d3c24"
|
||||
integrity sha1-EdCRMSI5648yyPJa6csAL/6NPCQ=
|
||||
|
||||
compressible@^2.0.0:
|
||||
version "2.0.18"
|
||||
resolved "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
|
||||
integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==
|
||||
dependencies:
|
||||
mime-db ">= 1.43.0 < 2"
|
||||
|
||||
compute-scroll-into-view@^1.0.17:
|
||||
version "1.0.17"
|
||||
resolved "https://registry.npmjs.org/compute-scroll-into-view/-/compute-scroll-into-view-1.0.17.tgz#6a88f18acd9d42e9cf4baa6bec7e0522607ab7ab"
|
||||
@ -10300,7 +10270,7 @@ http-errors@1.7.3, http-errors@~1.7.2:
|
||||
statuses ">= 1.5.0 < 2"
|
||||
toidentifier "1.0.0"
|
||||
|
||||
http-errors@^1.6.3, http-errors@^1.7.3:
|
||||
http-errors@^1.6.3, http-errors@^1.7.3, http-errors@^1.8.0:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz#75d1bbe497e1044f51e4ee9e704a62f28d336507"
|
||||
integrity sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==
|
||||
@ -12434,6 +12404,17 @@ koa-compose@^4.1.0:
|
||||
resolved "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz#507306b9371901db41121c812e923d0d67d3e877"
|
||||
integrity sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==
|
||||
|
||||
koa-compress@^5.1.0:
|
||||
version "5.1.0"
|
||||
resolved "https://registry.npmjs.org/koa-compress/-/koa-compress-5.1.0.tgz#7b9fe24f4c1b28d9cae90864597da472c2fcf701"
|
||||
integrity sha512-G3Ppo9jrUwlchp6qdoRgQNMiGZtM0TAHkxRZQ7EoVvIG8E47J4nAsMJxXHAUQ+0oc7t0MDxSdONWTFcbzX7/Bg==
|
||||
dependencies:
|
||||
bytes "^3.0.0"
|
||||
compressible "^2.0.0"
|
||||
http-errors "^1.8.0"
|
||||
koa-is-json "^1.0.0"
|
||||
statuses "^2.0.1"
|
||||
|
||||
koa-convert@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.npmjs.org/koa-convert/-/koa-convert-1.2.0.tgz#da40875df49de0539098d1700b50820cebcd21d0"
|
||||
@ -12442,6 +12423,11 @@ koa-convert@^1.2.0:
|
||||
co "^4.6.0"
|
||||
koa-compose "^3.0.0"
|
||||
|
||||
koa-is-json@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/koa-is-json/-/koa-is-json-1.0.0.tgz#273c07edcdcb8df6a2c1ab7d59ee76491451ec14"
|
||||
integrity sha1-JzwH7c3Ljfaiwat9We52SRRR7BQ=
|
||||
|
||||
koa-mount@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.npmjs.org/koa-mount/-/koa-mount-4.0.0.tgz#e0265e58198e1a14ef889514c607254ff386329c"
|
||||
@ -13393,6 +13379,11 @@ mime-db@1.49.0:
|
||||
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz#f3dfde60c99e9cf3bc9701d687778f537001cbed"
|
||||
integrity sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==
|
||||
|
||||
"mime-db@>= 1.43.0 < 2":
|
||||
version "1.50.0"
|
||||
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.50.0.tgz#abd4ac94e98d3c0e185016c67ab45d5fde40c11f"
|
||||
integrity sha512-9tMZCDlYHqeERXEHO9f/hKfNXhre5dK2eE/krIvUjZbS2KPcqGDfNShIWS1uW9XOTKQKqK6qbeOci18rbfW77A==
|
||||
|
||||
mime-match@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/mime-match/-/mime-match-1.0.2.tgz#3f87c31e9af1a5fd485fb9db134428b23bbb7ba8"
|
||||
@ -18657,6 +18648,11 @@ static-extend@^0.1.1:
|
||||
resolved "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
|
||||
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
|
||||
|
||||
statuses@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
|
||||
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==
|
||||
|
||||
stealthy-require@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
|
||||
@ -19554,24 +19550,6 @@ ts-node-dev@^1.1.8:
|
||||
ts-node "^9.0.0"
|
||||
tsconfig "^7.0.0"
|
||||
|
||||
ts-node@^10.2.1:
|
||||
version "10.2.1"
|
||||
resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz#4cc93bea0a7aba2179497e65bb08ddfc198b3ab5"
|
||||
integrity sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==
|
||||
dependencies:
|
||||
"@cspotcode/source-map-support" "0.6.1"
|
||||
"@tsconfig/node10" "^1.0.7"
|
||||
"@tsconfig/node12" "^1.0.7"
|
||||
"@tsconfig/node14" "^1.0.0"
|
||||
"@tsconfig/node16" "^1.0.2"
|
||||
acorn "^8.4.1"
|
||||
acorn-walk "^8.1.1"
|
||||
arg "^4.1.0"
|
||||
create-require "^1.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
yn "3.1.1"
|
||||
|
||||
ts-node@^9.0.0, ts-node@^9.1.1:
|
||||
version "9.1.1"
|
||||
resolved "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz#51a9a450a3e959401bda5f004a72d54b936d376d"
|
||||
|
Loading…
Reference in New Issue
Block a user