tachybase_todo/packages/server/src/index.ts

44 lines
986 B
TypeScript
Raw Normal View History

2021-04-01 23:51:00 +08:00
import { actions, middlewares } from '@nocobase/actions';
import Application from './application';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
import middleware from './middleware';
export * from './application';
export * from './middleware';
export default {
/**
*
*
* @param options
*/
create(options: any): Application {
console.log(options);
const app = new Application(options);
app.use(bodyParser());
app.use(cors());
2021-04-01 23:51:00 +08:00
app.resourcer.registerActionHandlers({ ...actions.common, ...actions.associate });
app.use(async (ctx, next) => {
ctx.db = app.database;
ctx.database = app.database;
await next();
});
2021-04-01 23:51:00 +08:00
app.resourcer.use(middlewares.associated);
app.use(middlewares.dataWrapping);
app.use(middleware({
database: app.database,
resourcer: app.resourcer,
...(options.resourcer||{}),
}));
return app;
}
}