tachybase_todo/packages/api/src/app.ts

67 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-01-04 13:17:16 +08:00
import path from 'path';
2021-03-23 10:53:11 +08:00
import dotenv from 'dotenv';
2021-04-01 09:58:30 +08:00
import Api from '@nocobase/server';
import actions from '@nocobase/actions';
import { middlewares } from '@nocobase/actions';
2021-01-04 13:17:16 +08:00
// @ts-ignore
const sync = global.sync || {
force: true,
2021-01-04 13:17:16 +08:00
alter: {
drop: true,
2021-01-04 13:17:16 +08:00
},
};
console.log('process.env.NOCOBASE_ENV', process.env.NOCOBASE_ENV);
2021-03-30 17:01:13 +08:00
dotenv.config({
path: path.resolve(__dirname, '../../../.env'),
});
2021-01-04 13:17:16 +08:00
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',
},
2021-03-26 10:06:36 +08:00
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
},
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
2021-01-04 13:17:16 +08:00
define: {},
sync,
},
resourcer: {
prefix: '/api',
},
});
2021-04-01 09:58:30 +08:00
api.resourcer.use(middlewares.associated);
2021-03-28 13:34:51 +08:00
api.resourcer.registerActionHandlers({ ...actions.common, ...actions.associate });
2021-01-04 13:17:16 +08:00
2021-04-01 09:58:30 +08:00
const plugins = [
'@nocobase/plugin-collections',
'@nocobase/plugin-action-logs',
'@nocobase/plugin-pages',
'@nocobase/plugin-users',
'@nocobase/plugin-file-manager',
'@nocobase/plugin-permissions',
'@nocobase/plugin-automations',
'@nocobase/plugin-china-region',
];
2021-01-04 13:17:16 +08:00
2021-04-01 09:58:30 +08:00
for (const plugin of plugins) {
api.registerPlugin(plugin, [require(`${plugin}/src/server`).default]);
}
2021-01-04 13:17:16 +08:00
export default api;