-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
46 lines (42 loc) · 1.26 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
const Hapi = require('hapi');
const HapiAuthJWT2 = require('hapi-auth-jwt2');
require('env2')('./.env');
const config = require('./config');
const routersShop = require('./routes/shops');
const routersOrders = require('./routes/orders');
const routersBargin = require('./routes/bargain');
const pluginHapiSwagger = require('./plugins/hapi-swagger');
const paginationPlugin = require('./plugins/hapi-pagination');
const routerUser = require('./routes/user');
const pluginHapiAuthJWT2 = require('./plugins/hapi-jwtAuth');
const logPlugin = require('./plugins/hapi-log');
const server = new Hapi.Server();
// 配置服务器启动host与端口
server.connection({
port: config.port,
host: config.host,
});
const init = async () => {
await server.register([
...pluginHapiSwagger,
paginationPlugin,
HapiAuthJWT2,
logPlugin,
]);
pluginHapiAuthJWT2(server);
server.route([
// 创建一个简单的hello hapi接口
...routersShop,
...routersOrders,
...routerUser,
...routersBargin,
]);
// 启动服务
await server.start();
server.log('info', `Server running at: ${server.info.uri}`);
};
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
init();