tachybase_todo/packages/server/src/index.ts

45 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-04-07 17:10:52 +08:00
import { actions, middlewares as m } from '@nocobase/actions';
import Application from './application';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
2021-04-07 17:10:52 +08:00
import { dbResourceRouter } from './middlewares';
export * from './application';
export * from './middleware';
2021-04-07 17:10:52 +08:00
export * as middlewares from './middlewares';
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-07 17:10:52 +08:00
app.resourcer.use(m.associated);
app.use(m.dataWrapping);
2021-04-07 17:10:52 +08:00
app.use(dbResourceRouter({
database: app.database,
resourcer: app.resourcer,
...(options.resourcer||{}),
}));
return app;
}
}