forked from graphql-kit/graphql-voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhapiLegacy.ts
37 lines (29 loc) · 796 Bytes
/
hapiLegacy.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
import renderVoyagerPage, { MiddlewareOptions } from './render-voyager-page';
const pkg = require('../package.json');
export interface Register {
(server, options, next): void;
attributes?: any;
}
const hapi: Register = function(server, options, next) {
if (arguments.length !== 3) {
throw new Error(`Voyager middleware expects exactly 3 arguments, got ${arguments.length}`);
}
const { path, route: config = {}, ...middlewareOptions } = options;
server.route({
method: 'GET',
path,
config,
handler: (_request, reply) => {
reply(renderVoyagerPage(<MiddlewareOptions>middlewareOptions)).header(
'Content-Type',
'text/html',
);
},
});
return next();
};
hapi.attributes = {
pkg,
multiple: false,
};
export default hapi;