67 lines
1.5 KiB
TypeScript
67 lines
1.5 KiB
TypeScript
import path from 'path';
|
|
import dotenv from 'dotenv';
|
|
import Api from '@nocobase/server';
|
|
import actions from '@nocobase/actions';
|
|
import { middlewares } from '@nocobase/actions';
|
|
|
|
// @ts-ignore
|
|
const sync = global.sync || {
|
|
force: true,
|
|
alter: {
|
|
drop: true,
|
|
},
|
|
};
|
|
|
|
console.log('process.env.NOCOBASE_ENV', process.env.NOCOBASE_ENV);
|
|
|
|
dotenv.config({
|
|
path: path.resolve(__dirname, '../../../.env'),
|
|
});
|
|
|
|
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',
|
|
},
|
|
pool: {
|
|
max: 5,
|
|
min: 0,
|
|
acquire: 30000,
|
|
idle: 10000,
|
|
},
|
|
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
|
|
define: {},
|
|
sync,
|
|
},
|
|
resourcer: {
|
|
prefix: '/api',
|
|
},
|
|
});
|
|
|
|
api.resourcer.use(middlewares.associated);
|
|
api.resourcer.registerActionHandlers({ ...actions.common, ...actions.associate });
|
|
|
|
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',
|
|
];
|
|
|
|
for (const plugin of plugins) {
|
|
api.registerPlugin(plugin, [require(`${plugin}/src/server`).default]);
|
|
}
|
|
|
|
export default api;
|