yi-ge / Koa2-API-Scaffold

一个基于Koa2的轻量级RESTful API Server脚手架。
Do What The F*ck You Want To Public License
766 stars 147 forks source link

这个脚手架怎么使用呢 #4

Closed sys2007 closed 6 years ago

sys2007 commented 6 years ago

怎么用呢?新手感觉无从下手啊。有没有样例什么的?还有就是我跑起来,测试路由都是返回Authentication Error 还需要什么权限吗?

Shijiuwei commented 6 years ago

同样不会用,JWT的token如何创建,客户端如果用postman get请求一个需要token的api的话,需要怎么在header里带上JWT生存的token信息,那么token如何获取呢~~

sys2007 commented 6 years ago

也是看的源码发现用到的JWT,这个token如何获取,怎么登录?

Shijiuwei commented 6 years ago

发现 app.js里的代码: .use(jwt({ secret: publicKey }).unless({ path: [/^\/public|\/user\/login|\/assets/] })) path 后面的表达式不能这么写。

改了为: .use(jwt({ secret: publicKey }).unless({ path: [/^\/public/, /^\/user/, /^\/login/, /^\/assets/] }))

yi-ge commented 6 years ago

@sys2007 @GangRock 我会给出一个具体的例子说明JWT在koa2的用法。

setsuna commented 6 years ago

koa2-API-scaffold\node_modules\koa-jwt\lib\index.js:17 const middleware = async function jwt(ctx, next) { ^^^^^^^^ SyntaxError: Unexpected token function at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Module._extensions..js (module.js:579:10) at Object.require.extensions.(anonymous function) [as .js] (D:\Repo\koa2-API-scaffold\node_modules\babel-register\lib\node.js:152:7) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) Application has crashed!

yi-ge commented 6 years ago

已更新。