Skip to content

Commit

Permalink
chore: refact
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Dec 12, 2023
1 parent 08f3c99 commit 1e5cfc6
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 36 deletions.
3 changes: 1 addition & 2 deletions packages/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { dirname, filename, join } from 'desm';
import jwt from 'jsonwebtoken';
import { join } from 'desm';

import { createApp } from './src/index';

Expand Down
3 changes: 1 addition & 2 deletions packages/app/src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
28 changes: 7 additions & 21 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import { createServer, combine, RpcServer } from '@tomrpc/core';
import type { IIndexServerConfig } from '@tomrpc/core';
import { combine, RpcServer } from '@tomrpc/core';

Check failure on line 1 in packages/app/src/index.ts

View workflow job for this annotation

GitHub Actions / build

Unable to resolve path to module '@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;
Expand All @@ -45,7 +27,7 @@ interface IJwt {
secret?: string;
issuer?: string;
debug: boolean;
unless?: any;
unless?: JSONValue;
getToken;
}
interface IAppConfig1 {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('lib', () => {
});

rpc.add({
'/add': function (a: string, b: string) {
'/add': function (a: string) {
return { a: a };
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('app', async () => {
});

rpc.add({
'/add': function (a: string, b: string) {
'/add': function (a: string) {
return { a: a };
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debug from 'debug';
// import debug from 'debug';
import supertest from 'supertest';
import { describe, expect, it, vi } from 'vitest';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ export class Plugable implements Strategy {

pre() {
return async (ctx, next) => {
log('pre');
log('pre ' + ctx.path);
await next();
log('pre end');
};
}

post() {
return async (ctx, next) => {
log('after');
log('after ' + ctx.path);
await next();
log('after end');
};
}

process() {
return async (ctx, next) => {
log('process default');
log('process default ' + ctx.path);
await next();
log('process default end');
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions packages/mount/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 1e5cfc6

Please sign in to comment.