-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathserver.js
More file actions
80 lines (62 loc) · 1.74 KB
/
Copy pathserver.js
File metadata and controls
80 lines (62 loc) · 1.74 KB
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
'use strict';
const Hapi = require('hapi');
const Boom = require('boom');
const Blipp = require('../');
const internals = {};
const init = async () => {
const server = new Hapi.Server();
await server.register({ plugin: Blipp, options: { showAuth: true } });
server.auth.scheme('custom', internals.scheme);
server.auth.strategy('stimpy', 'custom');
server.route({
method: 'GET',
path: '/user/{id}',
config: {
auth: 'stimpy',
description: 'Display user specific info',
handler: (request, h) => 'Something'
}
});
server.route({
method: 'GET',
path: '/user/{id}/profile',
config: {
auth: false,
description: 'Display user public info',
handler: (request, h) => 'Something'
}
});
server.route({
method: 'GET',
path: '/users',
config: {
auth: false,
description: 'List all users',
handler: (request, h) => 'Something'
}
});
server.route({
method: 'GET',
path: '/routes.table',
config: {
auth: false,
description: 'List routes table',
handler: (request, h) => {
return request.server.plugins.blipp.info();
}
}
});
await server.start();
};
init();
internals.scheme = function (server, options) {
return {
authenticate: function (request, h) {
const authorization = request.headers.authorization;
if (!authorization) {
throw Boom.unauthorized(null, 'Custom');
}
return h.authenticated({ credentials: { user: 'john' } });
}
};
};