You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

75 lines
1.7 KiB

import {
auth,
config,
method,
route,
swagger,
validate,
} from "@noderun/hapi-router";
import { Req, Res, ReturnValue } from "#/global";
import Joi from "joi";
import * as bcrypt from "bcrypt";
import glob from "fast-glob";
import path from "path";
export default class Index {
async css(request: Req, h: Res): ReturnValue {
return h.view("views/css.pug");
}
@auth("try")
async index(request: Req, h: Res): ReturnValue {
if (request.auth.isAuthenticated) {
// 登录了
} else {
// 未登录
}
return h.view("views/index.pug", { ss: request.auth.isAuthenticated });
}
@route("/about")
@auth(false)
async about(request: Req, h) {
console.log(request.auth);
console.log(1);
try {
const User = request.getModel("User");
console.log(await User.findOne({ where: { username: "xieyaxin" } }));
} catch (error) {
console.log(error);
}
console.log(2);
return h.view("views/about.ejs");
}
@auth()
@route("/docs/{path*}")
async docs(req: Req, h: Res): ReturnValue {
// const {id} = req.auth.credentials
// try {
// req.cookieAuth.ttl(720 * 24 * 60 * 60 * 1000)
// req.cookieAuth.set({ id: id });
// } catch (error) {
// console.log(error);
// }
if (req.path.endsWith(".md")) {
console.log(await glob(path.resolve(__dirname, "../../../docs/*.md")));
// 解析文档
return h.view("views/css.pug");
}
// 404页面
return h.redirect("/404");
}
@route("/{path*}")
async any(req: Req, h: Res): ReturnValue {
return h.view("404.pug");
}
@route("/404")
async 404(req: Req, h: Res): ReturnValue {
// 404页面
return h.view("404.pug");
}
}