diff --git a/packages/app/app.ts b/packages/app/app.ts index dbad115..d13d1d9 100644 --- a/packages/app/app.ts +++ b/packages/app/app.ts @@ -1,5 +1,4 @@ -import { dirname, filename, join } from 'desm'; -import jwt from 'jsonwebtoken'; +import { join } from 'desm'; import { createApp } from './src/index'; diff --git a/packages/app/src/__tests__/app.test.ts b/packages/app/src/__tests__/app.test.ts index 68403f1..dbdc032 100644 --- a/packages/app/src/__tests__/app.test.ts +++ b/packages/app/src/__tests__/app.test.ts @@ -1,5 +1,4 @@ -import { dirname, filename, join } from 'desm'; -import jwt from 'jsonwebtoken'; +import { join } from 'desm'; import supertest from 'supertest'; import { describe, expect, it } from 'vitest'; diff --git a/packages/app/src/index.ts b/packages/app/src/index.ts index 6d2682b..a75113a 100644 --- a/packages/app/src/index.ts +++ b/packages/app/src/index.ts @@ -1,31 +1,13 @@ -import { createServer, combine, RpcServer } from '@tomrpc/core'; -import type { IIndexServerConfig } from '@tomrpc/core'; +import { combine, RpcServer } from '@tomrpc/core'; +import type { IIndexServerConfig, JSONValue } from '@tomrpc/core'; // import mount from '@tomrpc/mount'; -import exp from 'constants'; import debug from 'debug'; -import { init } from './init'; -import { loadBuildinMiddlewaire, loadInitMiddleware } from './load'; import { Serve, Cors, View, Jwt } from './mw/index'; import { mergeDeep } from './utils'; const log = debug('@tomrpc/app'); -// { -// name:'hi' -// base: import.meta.url -// static: 'public' -// cors: { enable: true } -// view: { enable: true } -// jwt: { enable: true } -// port: 3000 -// mount: './fn' -// lifeCyle: { - -// }, -// debug: true -// logLevel: -// } interface ICors { enable?: boolean | false; opts?: object; @@ -45,7 +27,7 @@ interface IJwt { secret?: string; issuer?: string; debug: boolean; - unless?: any; + unless?: JSONValue; getToken; } interface IAppConfig1 { @@ -66,19 +48,23 @@ type IAppConfig = IAppConfig1 & IIndexServerConfig; export class AppServer extends RpcServer { constructor(cfg?: IAppConfig) { + log('AppServer constructor'); super(cfg); if (cfg?.buildin?.cors) { + log('cors enable'); const cors = new Cors(cfg?.buildin?.cors); this.plugin(cors); } if (cfg?.buildin?.serve) { + log('serve enable'); const serve = new Serve(cfg?.buildin?.serve); this.plugin(serve); } if (cfg?.buildin?.jwt) { + log('jwt enable'); const jwt = new Jwt(cfg?.buildin?.jwt); this.plugin(jwt); } diff --git a/packages/app/src/load.ts b/packages/app/src/load.ts index e7c9e9b..5f5c0ee 100644 --- a/packages/app/src/load.ts +++ b/packages/app/src/load.ts @@ -12,7 +12,7 @@ export async function loadInitMiddleware(rpc?, m?) { export async function loadBuildinMiddlewaire(rpc?) { // const buildin = rpc.config.buildin; - // log(rpc.config); + log(rpc.config); // log(buildin); // const mw = await import('./mw'); // for (const key in buildin) { diff --git a/packages/client/src/__tests__/index.test.ts b/packages/client/src/__tests__/index.test.ts index f1b268d..7fcd8a6 100644 --- a/packages/client/src/__tests__/index.test.ts +++ b/packages/client/src/__tests__/index.test.ts @@ -36,7 +36,7 @@ describe('lib', () => { }); rpc.add({ - '/add': function (a: string, b: string) { + '/add': function (a: string) { return { a: a }; }, }); diff --git a/packages/core/src/__tests__/app.test.ts b/packages/core/src/__tests__/app.test.ts index b5f9280..0e378e2 100644 --- a/packages/core/src/__tests__/app.test.ts +++ b/packages/core/src/__tests__/app.test.ts @@ -32,7 +32,7 @@ describe('app', async () => { }); rpc.add({ - '/add': function (a: string, b: string) { + '/add': function (a: string) { return { a: a }; }, }); diff --git a/packages/core/src/__tests__/proxy.test.ts b/packages/core/src/__tests__/proxy.test.ts index 5e00487..9d684cd 100644 --- a/packages/core/src/__tests__/proxy.test.ts +++ b/packages/core/src/__tests__/proxy.test.ts @@ -1,4 +1,4 @@ -import debug from 'debug'; +// import debug from 'debug'; import supertest from 'supertest'; import { describe, expect, it, vi } from 'vitest'; diff --git a/packages/core/src/fn.ts b/packages/core/src/fn.ts index 9cfa67a..f38dbca 100644 --- a/packages/core/src/fn.ts +++ b/packages/core/src/fn.ts @@ -49,7 +49,7 @@ export class Fn extends Plugable { } default() { - return async (ctx, next) => { + return async (ctx) => { log('default'); ctx.body = '[fn plugin] no fn repsonse, please check your fn if exist'; log('default end'); diff --git a/packages/core/src/plugin.ts b/packages/core/src/plugin.ts index e8abbc8..0ece437 100644 --- a/packages/core/src/plugin.ts +++ b/packages/core/src/plugin.ts @@ -70,7 +70,7 @@ export class Plugable implements Strategy { pre() { return async (ctx, next) => { - log('pre'); + log('pre ' + ctx.path); await next(); log('pre end'); }; @@ -78,7 +78,7 @@ export class Plugable implements Strategy { post() { return async (ctx, next) => { - log('after'); + log('after ' + ctx.path); await next(); log('after end'); }; @@ -86,7 +86,7 @@ export class Plugable implements Strategy { process() { return async (ctx, next) => { - log('process default'); + log('process default ' + ctx.path); await next(); log('process default end'); }; diff --git a/packages/core/src/server.ts b/packages/core/src/server.ts index 5649c6c..906090c 100644 --- a/packages/core/src/server.ts +++ b/packages/core/src/server.ts @@ -13,7 +13,7 @@ export const LifeCycleConfig = { before: [], load: [], after: [], - default: async (ctx, next) => { + default: async (ctx) => { log('default'); ctx.body = '[core server] no middleware repsonse, please check your route'; log('default end'); diff --git a/packages/mount/src/__tests__/index.test.ts b/packages/mount/src/__tests__/index.test.ts index e0b5549..502d424 100644 --- a/packages/mount/src/__tests__/index.test.ts +++ b/packages/mount/src/__tests__/index.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from 'vitest'; -import mount from '../mount'; +// import mount from '../mount'; describe('lib', () => { it('should render lib', () => { - // expect(lib()).toBe('lib'); + expect('lib').toBe('lib'); }); });