From cc8c7fcab33f653d411b406fdf92b769ebe1e4f0 Mon Sep 17 00:00:00 2001 From: 1549469775 <1549469775@qq.com> Date: Wed, 13 Jul 2022 10:41:22 +0800 Subject: [PATCH] fixed bug --- .prettierrc | 11 +++++++++++ packages/hapi-router/src/util/decorators.ts | 5 ++++- route.txt | 2 +- source/route/views/index/index.ts | 10 ++++++++-- source/route/views/login.ts | 1 + 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..d55c43f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "tabWidth": 4, + "useTabs": false, + "semi": false, + "singleQuote": false, + "trailingComma": "all", + "bracketSpacing": true, + "arrowParens": "avoid", + "htmlWhitespaceSensitivity": "ignore", + "printWidth": 120 +} \ No newline at end of file diff --git a/packages/hapi-router/src/util/decorators.ts b/packages/hapi-router/src/util/decorators.ts index 468b2a8..a2d72d6 100644 --- a/packages/hapi-router/src/util/decorators.ts +++ b/packages/hapi-router/src/util/decorators.ts @@ -1,5 +1,8 @@ // @ts-nocheck - +/** + * 方法 + * @param opts 参数 +*/ export function method(opts?:string|Array) { return function (target, propertyKey: string, descriptor: PropertyDescriptor) { target[propertyKey].$method = opts diff --git a/route.txt b/route.txt index b0d5ae6..00e8bea 100644 --- a/route.txt +++ b/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 diff --git a/source/route/views/index/index.ts b/source/route/views/index/index.ts index a25bc0d..34b3164 100644 --- a/source/route/views/index/index.ts +++ b/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"); } diff --git a/source/route/views/login.ts b/source/route/views/login.ts index b490b47..97ded49 100644 --- a/source/route/views/login.ts +++ b/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"; /**