Browse Source

fixed bug

dev
1549469775 3 years ago
parent
commit
cc8c7fcab3
  1. 11
      .prettierrc
  2. 5
      packages/hapi-router/src/util/decorators.ts
  3. 2
      route.txt
  4. 10
      source/route/views/index/index.ts
  5. 1
      source/route/views/login.ts

11
.prettierrc

@ -0,0 +1,11 @@
{
"tabWidth": 4,
"useTabs": false,
"semi": false,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"htmlWhitespaceSensitivity": "ignore",
"printWidth": 120
}

5
packages/hapi-router/src/util/decorators.ts

@ -1,5 +1,8 @@
// @ts-nocheck
/**
*
* @param opts
*/
export function method(opts?:string|Array<string>) {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
target[propertyKey].$method = opts

2
route.txt

@ -8,7 +8,7 @@ D:\1XYX\demo\hapi-demo\source\route\api对应路径:
需要权限 : DELETE /api/v1/user/del
需要权限 : GET /api/v1/user/userinfo
D:\1XYX\demo\hapi-demo\source\route\views对应路径:
不需权限 : GET /404
不需权限(提供无需验证): GET /404
不需权限 : GET /css
不需权限(提供无需验证): GET /
不需权限 : GET /about

10
source/route/views/index/index.ts

@ -67,10 +67,16 @@ export default class Index {
}
@route("/{path*}")
async any(req: Req, h: Res): ReturnValue {
return h.view("404.pug");
return h.redirect("/404");
}
@route("/404")
async 404(req: Req, h: Res): ReturnValue {
@auth("try")
async 404(request: Req, h: Res): ReturnValue {
if (request.auth.isAuthenticated) {
// 登录了
} else {
// 未登录
}
// 404页面
return h.view("404.pug");
}

1
source/route/views/login.ts

@ -1,4 +1,5 @@
import { Req, Res, ReturnValue } from "#/global";
import { gFail } from "@/util";
import { auth, config, method, route } from "@noderun/hapi-router";
import * as bcrypt from "bcrypt";
/**

Loading…
Cancel
Save