Skip to content

Commit

Permalink
feat: fix spelling mistake, support exception filter
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Mar 29, 2024
1 parent 47f7428 commit 1fee611
Show file tree
Hide file tree
Showing 45 changed files with 244 additions and 159 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
### Bug Fixes

* **@artusx/boilerplate-artusx-app:** fix missing method ([490fa49](https://github.com/artusjs/artusx/commit/490fa49b5c8b2af0b476fa3258533d5cb728aed1))
* **@artusx/plugin-schedule:** fix type of ArtusxSchedule ([edd27cb](https://github.com/artusjs/artusx/commit/edd27cb14f977ea1ae8b5087662d0a41b61283d5))
* **@artusx/plugin-schedule:** fix type of ArtusXSchedule ([edd27cb](https://github.com/artusjs/artusx/commit/edd27cb14f977ea1ae8b5087662d0a41b61283d5))



Expand Down
4 changes: 2 additions & 2 deletions packages/apps/artusx-express/src/controller/home.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import { GET, HTTPController } from '../types';
// import type { ArtusxContext } from '../types';
// import type { ArtusXContext } from '../types';

// @HTTPController()
// export default class HomeController {
// @GET('/')
// async home(ctx: ArtusxContext) {
// async home(ctx: ArtusXContext) {
// ctx.body = 'Hello World';
// }
// }
4 changes: 2 additions & 2 deletions packages/apps/artusx-grpc/src/chat-module/chat.schedule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject } from '@artus/core';
import { Schedule } from '@artusx/plugin-schedule';
import type { ArtusxSchedule } from '@artusx/plugin-schedule';
import type { ArtusXSchedule } from '@artusx/plugin-schedule';
import { ClientMessage } from '../proto-codegen/chat';
import ChatClient from './chat.client';

Expand All @@ -9,7 +9,7 @@ import ChatClient from './chat.client';
cron: '30 * * * * *',
runOnInit: true,
})
export default class NotifySchedule implements ArtusxSchedule {
export default class NotifySchedule implements ArtusXSchedule {
@Inject(ChatClient)
chatClient: ChatClient;

Expand Down
4 changes: 2 additions & 2 deletions packages/apps/artusx-grpc/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import type { ArtusxGrpcConfig } from '@artusx/plugin-grpc';
import type { ArtusXGrpcConfig } from '@artusx/plugin-grpc';

export default () => {
const grpc: ArtusxGrpcConfig = {
const grpc: ArtusXGrpcConfig = {
client: {
addr: '0.0.0.0:50051',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/artusx-grpc/src/echo-module/echo.schedule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject } from '@artus/core';
import { Schedule } from '@artusx/plugin-schedule';
import type { ArtusxSchedule } from '@artusx/plugin-schedule';
import type { ArtusXSchedule } from '@artusx/plugin-schedule';

import EchoClient from './echo.client';

Expand All @@ -9,7 +9,7 @@ import EchoClient from './echo.client';
cron: '30 * * * * *',
runOnInit: true,
})
export default class NotifySchedule implements ArtusxSchedule {
export default class NotifySchedule implements ArtusXSchedule {
@Inject(EchoClient)
echoClient: EchoClient;

Expand Down
54 changes: 27 additions & 27 deletions packages/apps/artusx-koa-bench/bench/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const path = require('path');

const koaRouterTemplate = `
import { Controller, GET } from '@artusx/core';
import type { ArtusxContext } from '@artusx/core';
import type { ArtusXContext } from '@artusx/core';
@Controller()
export default class BenchKoaRouterController {
@GET('/_health')
async koarouter_health(ctx: ArtusxContext) {
async koarouter_health(ctx: ArtusXContext) {
ctx.body = {};
}
Expand All @@ -18,7 +18,7 @@ export default class BenchKoaRouterController {

const findMyWayTemplate = `
import { Controller, GET } from '@artusx/core';
import type { ArtusxContext } from '@artusx/core';
import type { ArtusXContext } from '@artusx/core';
@Controller()
export default class BenchFindMyWayController {
Expand All @@ -33,7 +33,7 @@ export default class BenchFindMyWayController {
function genKoaRouterController(i) {
return `
@GET('/${i}/one')
async koarouter_one${i}(ctx: ArtusxContext) {
async koarouter_one${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -42,7 +42,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/one/two')
async koarouter_oneTwo${i}(ctx: ArtusxContext) {
async koarouter_oneTwo${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -51,7 +51,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/one/two/:three')
async koarouter_oneTwoThree${i}(ctx: ArtusxContext) {
async koarouter_oneTwoThree${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -60,7 +60,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/one/two/:three/:four?')
async koarouter_oneTwoThreeFour${i}(ctx: ArtusxContext) {
async koarouter_oneTwoThreeFour${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -69,7 +69,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/one/two/:three/:four?/five')
async koarouter_oneTwoThreeFourFive${i}(ctx: ArtusxContext) {
async koarouter_oneTwoThreeFourFive${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -78,7 +78,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/one/two/:three/:four?/five/six')
async koarouter_oneTwoThreeFourFiveSix${i}(ctx: ArtusxContext) {
async koarouter_oneTwoThreeFourFiveSix${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -87,7 +87,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/child')
async koarouter_child${i}(ctx: ArtusxContext) {
async koarouter_child${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -96,7 +96,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/child/grandchild')
async koarouter_childGrandchild${i}(ctx: ArtusxContext) {
async koarouter_childGrandchild${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -105,7 +105,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/child/grandchild/:id')
async koarouter_childGrandchildId${i}(ctx: ArtusxContext) {
async koarouter_childGrandchildId${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -114,7 +114,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/child/grandchild/:id/seven')
async koarouter_childGrandchildIdSeven${i}(ctx: ArtusxContext) {
async koarouter_childGrandchildIdSeven${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -123,7 +123,7 @@ function genKoaRouterController(i) {
}
@GET('/${i}/child/grandchild/:id/seven(/eight)?')
async koarouter_childGrandchildIdSevenEight${i}(ctx: ArtusxContext) {
async koarouter_childGrandchildIdSevenEight${i}(ctx: ArtusXContext) {
ctx.body = {
query: ctx.query,
params: ctx.params,
Expand All @@ -140,7 +140,7 @@ function genKoaRouterController(i) {
function genFindMyWayController(i) {
return `
@GET('/${i}/one/two/:three/:four/five/six')
async fmw_oneTwoThreeFourFiveSix${i}(ctx: ArtusxContext) {
async fmw_oneTwoThreeFourFiveSix${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -149,7 +149,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one/two/:three/:four/five')
async fmw_oneTwoThreeFourFive${i}(ctx: ArtusxContext) {
async fmw_oneTwoThreeFourFive${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -158,7 +158,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one/two/:three/:four')
async fmw_oneTwoThreeFour${i}(ctx: ArtusxContext) {
async fmw_oneTwoThreeFour${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -167,7 +167,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one/two1/:three?')
async fmw_oneTwo1Three${i}(ctx: ArtusxContext) {
async fmw_oneTwo1Three${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -176,7 +176,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one/two/:three')
async fmw_oneTwoThree${i}(ctx: ArtusxContext) {
async fmw_oneTwoThree${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -185,7 +185,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one/two')
async fmw_oneTwo${i}(ctx: ArtusxContext) {
async fmw_oneTwo${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -194,7 +194,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/one')
async fmw_one${i}(ctx: ArtusxContext) {
async fmw_one${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -203,7 +203,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/child/grandchild/:id/seven/eight')
async fmw_childGrandchildIdSevenEight${i}(ctx: ArtusxContext) {
async fmw_childGrandchildIdSevenEight${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -212,7 +212,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/child/grandchild/:id/seven')
async fmw_childGrandchildIdSeven${i}(ctx: ArtusxContext) {
async fmw_childGrandchildIdSeven${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -221,7 +221,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/child/grandchild/:id')
async fmw_childGrandchildId${i}(ctx: ArtusxContext) {
async fmw_childGrandchildId${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -230,7 +230,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/child/grandchild')
async fmw_childGrandchild${i}(ctx: ArtusxContext) {
async fmw_childGrandchild${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -239,7 +239,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}/child')
async fmw_child${i}(ctx: ArtusxContext) {
async fmw_child${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand All @@ -248,7 +248,7 @@ function genFindMyWayController(i) {
}
@GET('/${i}')
async fmw_index${i}(ctx: ArtusxContext) {
async fmw_index${i}(ctx: ArtusXContext) {
ctx.body = {
params: ctx.params,
query: ctx.query,
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/artusx-koa-bench/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArtusxConfig } from '@artusx/core';
import { ArtusXConfig } from '@artusx/core';

export default () => {
const artusx: ArtusxConfig = {
const artusx: ArtusXConfig = {
port: 7001,
middlewares: [],
};
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/artusx-koa-bench/src/controller/home.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Controller, GET } from '@artusx/core';

import type { ArtusxContext } from '@artusx/core';
import type { ArtusXContext } from '@artusx/core';

@Controller()
export default class HomeController {
@GET('/')
async home(ctx: ArtusxContext) {
async home(ctx: ArtusXContext) {
ctx.body = {
data: {
msg: 'artusx',
Expand Down
15 changes: 12 additions & 3 deletions packages/apps/artusx-koa/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os from 'os';
import fs from 'fs-extra';
import path from 'path';
import fs from 'fs-extra';

import {
ArtusxConfig,
ArtusXConfig,
LoggerOptions,
LoggerLevel,
Log4jsConfiguration,
Expand All @@ -12,6 +12,7 @@ import {
XtransitConfig,
} from '@artusx/core';

import type { ArtusXContext, ArtusXStdError } from '@artusx/core';
import type { EjsConfig } from '@artusx/plugin-ejs';
import type { RedisConfig } from '@artusx/plugin-redis';
import type { SequelizeConfig } from '@artusx/plugin-sequelize';
Expand All @@ -30,7 +31,7 @@ export default () => {
fs.ensureDirSync(logsDir);
fs.ensureDirSync(xprofilerLogDir);

const artusx: ArtusxConfig = {
const artusx: ArtusXConfig = {
keys: 'artusx-koa',
port: 7001,
middlewares: [LimitRate, checkAuth],
Expand All @@ -51,6 +52,14 @@ export default () => {
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
credentials: false,
},
onError: async (ctx: ArtusXContext, error: ArtusXStdError) => {
// ctx.throw(error?.status || 500, error);
ctx.body = {
code: error.status || 500,
message: error.message,
};
ctx.status = 200;
},
};

const redis: RedisConfig = {
Expand Down
Loading

0 comments on commit 1fee611

Please sign in to comment.