Skip to content

Commit

Permalink
fix: add jwt test
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Nov 13, 2023
1 parent 4f537ec commit c6df21f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 11 additions & 1 deletion packages/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createApp } from './src/index';
enable: true,
secret: 'shhhhhh',
debug: true,
unless: ['/public', '/a'],
unless: ['/public', '/api/*'],
},
view: {
enable: true,
Expand All @@ -34,6 +34,16 @@ import { createApp } from './src/index';
},
});

rpc.jwt(async (ctx, next) => {
// console.dir('view');
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) => {

Check warning on line 47 in packages/app/app.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

'next' is defined but never used
// console.dir('view');
ctx.state = {
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import debug from 'debug';

import { init } from './init';

Check warning on line 5 in packages/app/src/index.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

'init' is defined but never used
import { loadBuildinMiddlewaire, loadInitMiddleware } from './load';

Check warning on line 6 in packages/app/src/index.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

'loadBuildinMiddlewaire' is defined but never used

Check warning on line 6 in packages/app/src/index.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

'loadInitMiddleware' is defined but never used
import { Serve, Cors, View } from './mw/index';
import { Serve, Cors, View, Jwt } from './mw/index';

const log = debug('@tomrpc/app');

Check warning on line 9 in packages/app/src/index.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

'log' is assigned a value but never used

Expand Down Expand Up @@ -77,6 +77,8 @@ export async function createApp(cfg: IConfig) {
const view = new View(cfg.buildin.view);
rpc.plugin(view);

const jwt = new Jwt(cfg.buildin.view);
rpc.plugin(jwt);
// await mount(rpc, cfg.mount);
// await loadInitMiddleware(rpc, init);
// await loadBuildinMiddlewaire(rpc);
Expand All @@ -93,9 +95,13 @@ export async function createApp(cfg: IConfig) {
// }

return Object.assign(rpc, {
render: function (tpl, cb) {
jwt: function (cb) {
const mw = combine([cb]);
console.dir(rpc.config);
rpc.init.push(mw);
},
render: function (path, cb) {
const mw = combine([cb]);
rpc.load.push(mw);
},
});
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/mw/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class Jwt extends Plugable {

this.prefix = '';
this.name = 'jwt';
// this.init.push(this.a());
this.init.push(this.a());
}
a() {
return koajwt(this.config.opts).unless({ path: this.config.opts.unless });
}
// a() {
// return return koajwt(this.config.opts).unless({ path: this.config.opts.unless });
// }
}

0 comments on commit c6df21f

Please sign in to comment.