nocobase/packages/server/src/index.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-04-07 09:10:52 +00: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 09:10:52 +00:00
import { dbResourceRouter } from './middlewares';
export * from './application';
export * from './middleware';
2021-04-07 09:10:52 +00: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());
2021-08-13 01:57:21 +00:00
app.use(cors({
exposeHeaders: ['content-disposition'],
}));
2021-04-01 15:51:00 +00: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 09:10:52 +00:00
app.resourcer.use(m.associated);
app.use(m.dataWrapping);
2021-04-07 09:10:52 +00:00
app.use(dbResourceRouter({
database: app.database,
resourcer: app.resourcer,
...(options.resourcer||{}),
}));
return app;
}
}