This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 3 files changed +29
-0
lines changed
3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 59
59
"dependencies" : {
60
60
"@hapi/ammo" : " ^3.1.0" ,
61
61
"@hapi/boom" : " ^7.4.2" ,
62
+ "@hapi/h2o2" : " ^8.3.0" ,
62
63
"@hapi/hapi" : " ^18.3.1" ,
63
64
"@hapi/joi" : " ^15.0.1" ,
64
65
"array-shuffle" : " ^1.0.1" ,
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Joi = require ( '@hapi/joi' )
4
+ const Boom = require ( '@hapi/boom' )
4
5
const resources = require ( '../resources' )
6
+ const isIpfs = require ( 'is-ipfs' )
5
7
6
8
module . exports = [
7
9
{
@@ -39,5 +41,28 @@ module.exports = [
39
41
onPostHandler : { method : resources . gateway . afterHandler }
40
42
}
41
43
}
44
+ } ,
45
+ {
46
+ method : '*' ,
47
+ path : '/{path*}' ,
48
+ handler : {
49
+ proxy : {
50
+ mapUri : request => {
51
+ if ( ! isIpfs . ipfsSubdomain ( request . url . toString ( ) ) ) {
52
+ throw Boom . notFound ( )
53
+ }
54
+
55
+ const cid = request . url . hostname . split ( '.' ) [ 0 ]
56
+ let uri = `${ request . server . info . uri } /ipfs/${ cid } `
57
+
58
+ if ( request . url . pathname !== '/' ) {
59
+ uri += request . url . pathname
60
+ }
61
+
62
+ console . log ( `${ request . url } -> ${ uri } ` )
63
+ return { uri }
64
+ }
65
+ }
66
+ }
42
67
}
43
68
]
Original file line number Diff line number Diff line change 2
2
3
3
const Hapi = require ( '@hapi/hapi' )
4
4
const Pino = require ( 'hapi-pino' )
5
+ const H2o2 = require ( '@hapi/h2o2' )
5
6
const debug = require ( 'debug' )
6
7
const multiaddr = require ( 'multiaddr' )
7
8
const toMultiaddr = require ( 'uri-to-multiaddr' )
@@ -133,6 +134,8 @@ class HttpApi {
133
134
}
134
135
} )
135
136
137
+ await server . register ( H2o2 )
138
+
136
139
server . route ( require ( './gateway/routes' ) )
137
140
138
141
return server
You can’t perform that action at this time.
0 commit comments