Skip to content

Commit

Permalink
chore: stash
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Nov 15, 2023
1 parent ab44ca8 commit f506fa6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
34 changes: 17 additions & 17 deletions packages/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,32 +29,32 @@ 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');
ctx.state = {
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变成插件
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ interface IConfig {
view?: IView;
jwt?: IJwt;
};
beforeAll: any;
}
export async function createApp(cfg: IConfig) {
const rpc = createServer(
Expand All @@ -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);
Expand All @@ -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) {
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 @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface Strategy {
name;
app;
compose;
proxy;
config;
server;
serverConfig;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f506fa6

Please sign in to comment.