tachybase_todo/examples/resources/src/index.ts

66 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-09-16 00:37:43 +08:00
import { Application } from '@nocobase/server/src';
import path from 'path';
const keys = __dirname.split(path.sep);
const slug = keys[keys.length - 2];
const options = {
database: {
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,
dialect: process.env.DB_DIALECT as any,
dialectOptions: {
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
},
hooks: {
beforeDefine(model, options) {
options.tableName = `examples_${slug}_${options.tableName || options.name.plural}`;
},
},
},
resourcer: {
prefix: `/api/examples/${slug}`,
},
};
console.log(options);
const app = new Application(options);
app.resource({
name: 'server',
actions: {
async getTime(ctx, next) {
ctx.body = new Date();
await next();
}
},
});
app.parse(process.argv);
/*
yarn examples simple db sync
yarn examples simple start
curl --location --request POST 'http://localhost:3000/api/examples/simple/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "abc",
"password": "123456"
}'
curl --location --request GET 'http://localhost:5051/api/examples/simple/users'
*/