1549469775 3 years ago
parent
commit
0f439c1211
  1. 1
      docs/a.md
  2. 41362
      log/SQL.log
  3. 2
      package.json
  4. 2
      packages/hapi-router/dist/hapi-router.cjs.js
  5. 2
      packages/hapi-router/dist/hapi-router.cjs.js.map
  6. 2
      packages/hapi-router/src/index.ts
  7. 3
      public/css/page/a.css
  8. 2
      public/css/page/a.styl
  9. 3
      public/css/page/css.css
  10. 8
      route.txt
  11. 2
      source/auth/index.ts
  12. 24
      source/models/Constant.ts
  13. 1
      source/route/api/user/index.ts
  14. 2
      source/route/index/color.ts
  15. 40
      source/route/index/index.ts
  16. 9
      source/route/nav/index.ts
  17. 2
      source/run.ts
  18. 2
      template/views/index.pug

1
docs/a.md

@ -0,0 +1 @@
sdad

41362
log/SQL.log

File diff suppressed because it is too large

2
package.json

@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"init": "ts-node --respawn --project ./tsconfig.json -r tsconfig-paths/register source/db/init.ts alter",
"start": "ts-node-dev --respawn --project ./tsconfig.json -r tsconfig-paths/register ./source/main.ts",
"start": "ts-node-dev --watch ./source/route --ignore-watch ./source/route/route.txt --respawn --project ./tsconfig.json -r tsconfig-paths/register ./source/main.ts",
"dev": "npm start",
"deva": "nodemon --exec 'ts-node --project ./tsconfig.json -r tsconfig-paths/register ./source/main.ts'"
},

2
packages/hapi-router/dist/hapi-router.cjs.js

@ -302,7 +302,7 @@ var routePlugin = (function () {
}
}
});
fs.writeFileSync(path.resolve(sourceDir, "route.txt"), routes.join("\n"), {
fs.writeFileSync(path.resolve(process.cwd(), "route.txt"), routes.join("\n"), {
encoding: "utf-8",
});
};

2
packages/hapi-router/dist/hapi-router.cjs.js.map

File diff suppressed because one or more lines are too long

2
packages/hapi-router/src/index.ts

@ -103,7 +103,7 @@ class routePlugin {
}
}
});
fs.writeFileSync(path.resolve(sourceDir, "route.txt"), routes.join("\n"), {
fs.writeFileSync(path.resolve(process.cwd(), "route.txt"), routes.join("\n"), {
encoding: "utf-8",
});
}

3
public/css/page/a.css

@ -0,0 +1,3 @@
body {
color: #008000;
}

2
public/css/page/a.styl

@ -0,0 +1,2 @@
body
color: green;

3
public/css/page/css.css

@ -16,9 +16,6 @@ html, body{
.title{
padding-left: 20px;
position: sticky;
top: 0;
background-color: white;
z-index: 10;
}

8
source/route/route.txt → route.txt

@ -1,4 +1,5 @@
所有路由路径:
不需权限: GET /ad
需要权限: GET /api/upload
需要权限: POST /api/upload/upload
不需权限: POST /api/user/register
@ -7,9 +8,12 @@
需要权限: DELETE /api/user/del
需要权限: GET /api/user/userinfo
不需权限: GET /index/color
不需权限: GET /{path*}
不需权限: GET /404
不需权限: GET /css
需要权限: GET /
不需权限: GET /login
不需权限: POST /login
不需权限: GET /about
不需权限: GET /about
需要权限: GET /docs/{path*}
不需权限: GET /{path*}
不需权限: GET /nav

2
source/auth/index.ts

@ -14,6 +14,8 @@ export async function validateJwt(decoded, request: Req, h) {
}
export async function validateSession(request: Req, session) {
console.log(request.path);
console.log(session);
console.log(`session id: ${session.id}`);
const User = request.getModel("User")
if (session.id) {

24
source/models/Constant.ts

@ -0,0 +1,24 @@
module.exports = function (sequelize, DataTypes) {
const Constant = sequelize.define(
"Constant",
{
// 键
key: {
type: DataTypes.STRING
},
// 值
value: {
type: DataTypes.STRING,
allowNull: true
},
describe: {
type: DataTypes.STRING,
allowNull: true
},
},
{
timestamps: false,
}
);
return Constant
};

1
source/route/api/user/index.ts

@ -97,7 +97,6 @@ export default class {
})
@swagger("获取用户信息", "返回注册用户的信息", ["用户操作", "api"])
async userinfo(request: Req, h: Res): ReturnValue {
console.log(request);
const { id } = request.auth.credentials;
const User = request.getModel("User")
let result = <any>await User.findOne({ where: { id: id } });

2
source/route/index/color.ts

@ -2,6 +2,6 @@
export default class {
index(req, h){
}
}

40
source/route/index/index.ts

@ -9,12 +9,12 @@ import {
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")
async css(request: Req, h: Res): ReturnValue {
return h.view("views/css.pug");
}
@auth()
@ -29,7 +29,7 @@ export default class Index {
} else {
// 未登录
}
return h.view("views/index.pug");
return h.view("views/index.pug", { ss: request.auth.isAuthenticated });
}
@method("GET")
@route("/login")
@ -42,13 +42,12 @@ export default class Index {
@route("/login")
async login(request: Req, h: Res): ReturnValue {
const { username, password } = request.payload as any;
const User = request.getModel("User")
const User = request.getModel("User");
const account = <any>await User.findOne({ where: { username: username } });
if (!account || !(await bcrypt.compare(password, account.password))) {
return h.redirect("/login");
}
request.cookieAuth.set({ id: account.id });
return h.redirect("/");
@ -56,7 +55,7 @@ export default class Index {
@route("/about")
@auth(false)
async about(request, h) {
async about(request: Req, h) {
console.log(request.auth);
console.log(1);
@ -71,8 +70,31 @@ export default class Index {
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 404(req, h) {
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");
}

9
source/route/nav/index.ts

@ -0,0 +1,9 @@
import { Req, Res, ReturnValue } from "#/global";
import { gSuccess } from "@/util";
export default class Nav {
async index(req: Req, h: Res): ReturnValue{
const Constant = req.getModel("Constant")
return gSuccess("31231")
}
}

2
source/run.ts

@ -11,7 +11,7 @@ import { Sequelize } from "sequelize";
const run = async (): Promise<Server> => {
const server = Hapi.server({
port: 3000,
port: 3388,
host: "localhost",
});

2
template/views/index.pug

@ -9,6 +9,6 @@ block head
block content
.container
h1.title 终是无缘一别两欢
h1.title 终是无缘一别两欢#{ss}
div.word 昨天看了我初中喜欢的人在空间发的一篇关于怀念初中的短篇小说吧,记录了他对一些记忆深刻的人的评价,而我也看到了我明明一直清楚,却不肯打心底接受的真相,他喜欢另外一个人,过往那么多的蛛丝马迹,那么多明明一件事就能看出他喜欢的人是她的真相,可我却是宁愿找借口自欺欺人,而今他给出坦白答案,他是放下了,才说出来,我是不是也该放下了,直到今日才明白我一个人自以为刻骨铭心的回忆,他也许早就忘怀,他的短篇小说故事中我没有丝言片语,也许若干年后他回想起来的只是我的名字,我只是个戏子,在他的故事中流着自己的泪,一个于他青春年华中不曾使他掀起过一丝波澜的模糊影子,而他不知道也永远不会知道,我的故事里他出现的很多,占了很多篇幅,我把他写进我的故事,因为他路过我心上,他踏着万千星河而来,又乘舟奔赴远方,我与春风皆过客,你携秋水揽星河。如今看来万般故事不过情伤,易水人去,明月如霜。
div.word(href="232") 他是无意穿堂风,却偏偏孤据引山洪。我是垂眉摆渡翁,却独独偏爱哝。
Loading…
Cancel
Save