2022-08-16 14:41:29 +08:00
|
|
|
/*
|
|
|
|
# 最简单的单应用
|
|
|
|
|
|
|
|
# 步骤
|
|
|
|
|
|
|
|
Step 1:
|
|
|
|
yarn run:example app/single-app start
|
|
|
|
|
|
|
|
Step 2:
|
|
|
|
curl http://localhost:13000/api/test:list
|
|
|
|
*/
|
2022-08-08 14:42:48 +08:00
|
|
|
import { Application } from '@nocobase/server';
|
2022-09-18 14:10:01 +08:00
|
|
|
import { uid } from '@nocobase/utils';
|
2022-08-08 14:42:48 +08:00
|
|
|
|
|
|
|
const app = new Application({
|
|
|
|
database: {
|
|
|
|
logging: process.env.DB_LOGGING === 'on' ? console.log : false,
|
|
|
|
dialect: process.env.DB_DIALECT as any,
|
|
|
|
storage: process.env.DB_STORAGE,
|
|
|
|
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 as any,
|
|
|
|
timezone: process.env.DB_TIMEZONE,
|
2022-09-18 14:10:01 +08:00
|
|
|
tablePrefix: `t_${uid()}_`,
|
2022-08-08 14:42:48 +08:00
|
|
|
},
|
|
|
|
resourcer: {
|
|
|
|
prefix: '/api',
|
|
|
|
},
|
|
|
|
plugins: [],
|
|
|
|
});
|
|
|
|
|
2022-08-16 14:41:29 +08:00
|
|
|
// 定义了一个 test 资源,并提供了相对应的 list 方法
|
2022-08-08 14:42:48 +08:00
|
|
|
app.resource({
|
|
|
|
name: 'test',
|
|
|
|
actions: {
|
2022-08-16 14:41:29 +08:00
|
|
|
async list(ctx, next) {
|
2022-08-08 14:42:48 +08:00
|
|
|
ctx.body = 'test list';
|
2022-08-16 14:41:29 +08:00
|
|
|
await next();
|
2022-09-18 14:10:01 +08:00
|
|
|
process.stdout.write('rs');
|
2022-08-08 14:42:48 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
app.runAsCLI();
|
|
|
|
}
|
|
|
|
|
|
|
|
export default app;
|