tachybase_todo/packages/api/src/index.ts

26 lines
851 B
TypeScript
Raw Normal View History

import api from './app';
2021-04-07 17:10:52 +08:00
import { middlewares } from '@nocobase/server';
2020-12-15 14:32:56 +08:00
2020-12-18 19:54:53 +08:00
(async () => {
2021-04-07 17:10:52 +08:00
api.resourcer.use(middlewares.actionParams());
2021-09-05 14:17:45 +08:00
api.on('plugins.afterLoad', async () => {
console.log('plugins.afterLoad')
if (process.env.NOCOBASE_ENV === 'demo') {
api.resourcer.use(middlewares.demoBlacklistedActions({
emails: [process.env.ADMIN_EMAIL],
}));
}
api.use(middlewares.appDistServe({
root: process.env.APP_DIST,
useStaticServer: !(process.env.APP_USE_STATIC_SERVER === 'false' || !process.env.APP_USE_STATIC_SERVER),
2021-04-07 17:10:52 +08:00
}));
2021-04-07 17:37:14 +08:00
});
2021-09-05 14:17:45 +08:00
const start = Date.now();
await api.start(process.env.API_PORT);
console.log(api.database.getTables().map(t => t.getName()));
console.log(`Start-up time: ${(Date.now() - start) / 1000}s`);
console.log(`http://localhost:${process.env.API_PORT}/`);
})();