-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
108 lines (94 loc) · 2.85 KB
/
index.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import * as Hapi from "hapi";
const Bcrypt = require('bcrypt');
import { Routes } from './routes/routes';
const config = require('./config/config');
const server = new Hapi.Server({
host: config.application.host,
port: config.application.port,
routes: {
cors: true,
json: {
space: 4
}
}
});
const validate = async (request, username, password) => {
return new Promise(
(resolve, reject) => {
if (username === 'jgichuhi' && password === 'jecihjoy2018')
resolve({ isValid: true, credentials: {} })
else resolve({ isValid: false, credentials: {} })
});
};
const init = async function () {
await server.register([
require("inert"),
require("vision"),
require('hapi-auth-basic'),
{
plugin: require("hapi-swagger"),
options: {
info: {
title: "Customer Order Api",
description: "Customer Api Documentation",
version: "1.0"
},
tags: [
{
name: "tasks",
description: "Api tasks interface."
},
{
name: "users",
description: "Api users interface."
}
],
sortEndpoints: 'path',
swaggerUI: true,
documentationPage: true,
documentationPath: "/docs"
}
},
{
plugin: require("good"),
options: {
ops: {
interval: 1000
},
reporters: {
consoleReporter: [
{
module: "good-squeeze",
name: "Squeeze",
args: [
{
error: "*",
log: "*",
response: "*",
request: "*"
}
]
},
{
module: "good-console"
},
"stdout"
]
}
}
}
]);
server.auth.strategy('simple', 'basic', { validate });
for (var route in Routes) {
server.route(Routes[route]);
}
// causes all routes to require authentication
server.auth.default('simple');
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
init();
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});