mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 05:08:42 +08:00
dcdb21d398
* api/ui 改名为 server/client * 微调 * 继续完善 pages * Fix env file and file mode. (#1) * Fix: ignore .env file and environment variable names. * Fix: correct file mode. * fix: put environment variables together * fix: separate data and ui resourcer * feat: collection loader * feat: redirectTo * feat: fields & actions & views * feat: fields & actions * feat: app & pages & collections... * feat: collections & pages & permissions... * Doc: add readme (#2) * Doc: add README.md. * Util: add .editorconfig. * Fix: use glob ignore option instead of additional checking. (#3) * Fix: typo. (#4) * feat: permissions * feat: getCollection & getView actions * refactor: code cleanup Co-authored-by: Junyi <mytharcher@users.noreply.github.com>
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import Api from '../src';
|
|
import dotenv from 'dotenv';
|
|
import path from 'path';
|
|
import Database from '@nocobase/database';
|
|
|
|
const sync = {
|
|
force: true,
|
|
alter: {
|
|
drop: true,
|
|
},
|
|
};
|
|
|
|
dotenv.config();
|
|
|
|
const api = Api.create({
|
|
database: {
|
|
username: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_DATABASE,
|
|
host: process.env.DB_HOST,
|
|
port: process.env.DB_PORT,
|
|
dialect: process.env.DB_DIALECT,
|
|
dialectOptions: {
|
|
charset: 'utf8mb4',
|
|
collate: 'utf8mb4_unicode_ci',
|
|
},
|
|
logging: false,
|
|
define: {},
|
|
sync,
|
|
},
|
|
resourcer: {
|
|
prefix: '/api',
|
|
},
|
|
});
|
|
|
|
(async () => {
|
|
await api
|
|
.plugins([
|
|
[path.resolve(__dirname, '../../plugin-collections'), {}],
|
|
[path.resolve(__dirname, '../../plugin-pages'), {}],
|
|
// [require('../../plugin-collections/src/index').default, {}],
|
|
// [require('../../plugin-pages/src/index').default, {}],
|
|
]);
|
|
|
|
const database: Database = api.database;
|
|
|
|
const Collection = database.getModel('collections');
|
|
const tables = database.getTables([]);
|
|
|
|
for (let table of tables) {
|
|
const options = table.getOptions();
|
|
const collection = await Collection.create({
|
|
name: options.name,
|
|
title: options.title,
|
|
});
|
|
await collection.updateAssociations({
|
|
fields: options.fields.map(field => {
|
|
return {
|
|
type: field.type,
|
|
name: field.name,
|
|
options: field,
|
|
};
|
|
}),
|
|
});
|
|
}
|
|
|
|
// const collections = await Collection.findAll();
|
|
|
|
// await Promise.all(collections.map(async (collection) => {
|
|
// return await collection.modelInit();
|
|
// }));
|
|
|
|
api.listen(23001, () => {
|
|
console.log('http://localhost:23001/');
|
|
});
|
|
})();
|