2020-11-11 15:23:39 +08:00
|
|
|
import Api from '../../../server/src';
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
import path from 'path';
|
2020-11-13 22:01:14 +08:00
|
|
|
import actions from '../../../actions/src';
|
|
|
|
import associated from '../../../actions/src/middlewares/associated';
|
2020-11-11 15:23:39 +08:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-08 10:02:41 +08:00
|
|
|
api.resourcer.use(async (ctx, next) => {
|
|
|
|
const { resourceName } = ctx.action.params;
|
|
|
|
const table = ctx.db.getTable(resourceName);
|
2020-12-08 14:33:28 +08:00
|
|
|
ctx.state.developerMode = false;
|
2020-12-08 10:02:41 +08:00
|
|
|
if (table && table.hasField('developerMode')) {
|
2020-12-08 14:33:28 +08:00
|
|
|
ctx.action.setParam('filter.developerMode', ctx.state.developerMode);
|
2020-12-08 10:02:41 +08:00
|
|
|
}
|
|
|
|
await next();
|
|
|
|
});
|
2020-11-13 22:01:14 +08:00
|
|
|
api.resourcer.use(associated);
|
2020-12-02 13:48:19 +08:00
|
|
|
api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
2020-11-13 22:01:14 +08:00
|
|
|
|
2020-11-11 15:23:39 +08:00
|
|
|
(async () => {
|
|
|
|
await api
|
|
|
|
.plugins([
|
|
|
|
[path.resolve(__dirname, '../../../plugin-collections'), {}],
|
|
|
|
[path.resolve(__dirname, '../../../plugin-pages'), {}],
|
|
|
|
[path.resolve(__dirname, '../../../plugin-users'), {}],
|
2020-12-07 08:51:50 +08:00
|
|
|
// [path.resolve(__dirname, '../../../plugin-permissions'), {}],
|
|
|
|
// [path.resolve(__dirname, '../../../plugin-file-manager'), {}],
|
2020-11-11 15:23:39 +08:00
|
|
|
]);
|
|
|
|
|
2020-12-08 10:02:41 +08:00
|
|
|
// await api.database.getModel('collections').load();
|
|
|
|
|
2020-11-11 15:23:39 +08:00
|
|
|
api.listen(process.env.HTTP_PORT, () => {
|
|
|
|
console.log(`http://localhost:${process.env.HTTP_PORT}/`);
|
|
|
|
});
|
|
|
|
})();
|