-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
87 lines (77 loc) · 1.72 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
const Hapi = require("hapi");
const Pack = require("./package");
const Vision = require("@hapi/vision");
const Path = require("path");
const server = Hapi.server({
port: require("./config").http,
host: "localhost",
routes: {
files: {
relativeTo: Path.join(__dirname, "public")
}
}
});
var validate = function(decodedToken, callback) {
return { isValid: true };
};
const init = async () => {
server.state("token", {
ttl: null, // 时效
isSecure: false, // https
isHttpOnly: false, // http Only
encoding: "none", // encode
clearInvalid: false, // 移除不可用的 cookie
strictHeader: true // 不允许违反 RFC 6265
});
await server.register([
require("inert"),
require("@hapi/vision"),
require("hapi-auth-jwt2"),
{
plugin: require("hapi-swagger"),
options: {
info: {
title: "Marx Server Document",
version: Pack.version
}
}
}
// {
// plugin: require("hapi-pino"),
// options: {
// prettyPrint: true
// }
// }
]);
server.auth.strategy("jwt", "jwt", {
key: "NeverShareYourSecret", // Never Share your secret key
validate,
cookieKey: "token"
});
server.auth.default("jwt");
server.route([
{
method: "GET",
path: "/{param*}",
config: {
auth: false
},
handler: {
directory: {
path: "."
// redirectToSlash: true
}
}
},
...require("./routes/user"),
...require("./routes/test")
]);
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
process.on("unhandledRejection", err => {
console.log(err);
process.exit(1);
});
init();