From f506fa6b315709a9fbe697c582e0086735eb6677 Mon Sep 17 00:00:00 2001 From: npmstudy Date: Wed, 15 Nov 2023 19:48:53 +0800 Subject: [PATCH] chore: stash --- packages/app/app.ts | 34 +++++++++++++++++----------------- packages/app/src/index.ts | 5 ++--- packages/core/src/fn.ts | 2 +- packages/core/src/plugin.ts | 16 ---------------- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/packages/app/app.ts b/packages/app/app.ts index f90bbcf..7362720 100644 --- a/packages/app/app.ts +++ b/packages/app/app.ts @@ -17,7 +17,7 @@ import { createApp } from './src/index'; enable: true, secret: 'shhhhhh', debug: true, - unless: { path: ['/public', '/view', '/', '/api/*'] }, + unless: { path: ['/view'] }, }, view: { enable: true, @@ -29,24 +29,20 @@ import { createApp } from './src/index'; }, }, }, - beforeAll: async (ctx, next) => { - // console.dir(ctx.jwt); - await next(); - }, }); - rpc.jwt(async (ctx, next) => { - const secret = 'shhhhhh'; - const token = jwt.sign({ foo: 'bar' }, secret); - console.dir(ctx.path); + // rpc.jwt(async (ctx, next) => { + // const secret = 'shhhhhh'; + // const token = jwt.sign({ foo: 'bar' }, secret); + // console.dir(ctx.path); - await next(); - // if (['/', '/view', '/api*'].some((e) => ctx.path.match(e))) { - // await next(); - // } else { - // ctx.body = { jwt: 'not jwt' }; - // } - }); + // await next(); + // // if (['/', '/view', '/api*'].some((e) => ctx.path.match(e))) { + // // await next(); + // // } else { + // // ctx.body = { jwt: 'not jwt' }; + // // } + // }); rpc.render('/view', async (ctx, next) => { // console.dir('view'); @@ -54,7 +50,11 @@ import { createApp } from './src/index'; session: ctx.session, title: 'app', }; - await ctx.render('user.ejs', { user: { name: 'alfred' } }); + if (ctx.path === '/view') { + await ctx.render('user.ejs', { user: { name: 'alfred' } }); + } else { + await next(); + } }); // rpc.view vs rpc.fn变成插件 diff --git a/packages/app/src/index.ts b/packages/app/src/index.ts index e750c80..004c6e8 100644 --- a/packages/app/src/index.ts +++ b/packages/app/src/index.ts @@ -56,7 +56,6 @@ interface IConfig { view?: IView; jwt?: IJwt; }; - beforeAll: any; } export async function createApp(cfg: IConfig) { const rpc = createServer( @@ -78,7 +77,7 @@ export async function createApp(cfg: IConfig) { rpc.plugin(view); const jwt = new Jwt(cfg.buildin.jwt); - rpc.plugin(jwt); + // rpc.plugin(jwt); // await mount(rpc, cfg.mount); // await loadInitMiddleware(rpc, init); // await loadBuildinMiddlewaire(rpc); @@ -97,7 +96,7 @@ export async function createApp(cfg: IConfig) { return Object.assign(rpc, { jwt: function (cb) { const mw = combine([cb]); - console.dir(rpc.config); + // console.dir(rpc.config); rpc.init.push(mw); }, render: function (path, cb) { diff --git a/packages/core/src/fn.ts b/packages/core/src/fn.ts index abb4812..d9ebca3 100644 --- a/packages/core/src/fn.ts +++ b/packages/core/src/fn.ts @@ -66,7 +66,7 @@ export class Fn extends Plugable { if (routers[key]) { const args = [...param, ctx]; - // console.dir(args); + console.dir(`call fn ${ctx.path}, with [${param}]`); const result = routers[key].apply(ctx, args); // console.dir(result); ctx.body = result; diff --git a/packages/core/src/plugin.ts b/packages/core/src/plugin.ts index b883f4d..beb507d 100644 --- a/packages/core/src/plugin.ts +++ b/packages/core/src/plugin.ts @@ -15,7 +15,6 @@ export interface Strategy { name; app; compose; - proxy; config; server; serverConfig; @@ -56,21 +55,6 @@ export class Plugable implements Strategy { return ctx[this.name]; } - proxy() { - return async (ctx, next) => { - console.dir('proxy prefix=' + this.prefix); - if (ctx.path.match(this.prefix)) { - console.dir('proxy ' + ctx.path); - await next(); - console.dir('proxy end ' + ctx.path); - } else { - console.dir('not proxy ' + ctx.path); - await next(); - console.dir('not proxy end ' + ctx.path); - } - }; - } - getMiddleware() { // console.dir('getMiddleware'); const pre = this.pre();