Skip to content

Commit 3d6027a

Browse files
fbaiodiashackergrrl
authored andcommitted
Register routes on the injected server
1 parent 768cfc4 commit 3d6027a

File tree

9 files changed

+125
-105
lines changed

9 files changed

+125
-105
lines changed

src/http-api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exports.start = (callback) => {
4646
server.connection({ host: gateway[2], port: gateway[4], labels: 'Gateway' })
4747

4848
// load routes
49-
require('./routes')
49+
require('./routes')(server)
5050

5151
server.start((err) => {
5252
if (err) {

src/http-api/routes/block.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

43
// TODO
4+
module.exports = (server) => {
5+
const api = server.select('API')
56

6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/block',
9-
handler: resources.block
10-
})
7+
api.route({
8+
method: 'GET',
9+
path: '/api/v0/block',
10+
handler: resources.block
11+
})
12+
}

src/http-api/routes/bootstrap.js

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32
const Joi = require('joi')
43

5-
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L818
6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/bootstrap',
9-
handler: resources.bootstrap.list
10-
})
4+
module.exports = (server) => {
5+
const api = server.select('API')
116

12-
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
13-
api.route({
14-
method: 'GET',
15-
path: '/api/v0/bootstrap/add',
16-
handler: resources.bootstrap.add,
17-
config: {
18-
validate: {
19-
query: {
20-
arg: Joi.string().required(), // multiaddr to add
21-
default: Joi.boolean()
7+
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L818
8+
api.route({
9+
method: 'GET',
10+
path: '/api/v0/bootstrap',
11+
handler: resources.bootstrap.list
12+
})
13+
14+
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
15+
api.route({
16+
method: 'GET',
17+
path: '/api/v0/bootstrap/add',
18+
handler: resources.bootstrap.add,
19+
config: {
20+
validate: {
21+
query: {
22+
arg: Joi.string().required(), // multiaddr to add
23+
default: Joi.boolean()
24+
}
2225
}
2326
}
24-
}
25-
})
27+
})
2628

27-
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
28-
api.route({
29-
method: 'GET',
30-
path: '/api/v0/bootstrap/list',
31-
handler: resources.bootstrap.list
32-
})
29+
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
30+
api.route({
31+
method: 'GET',
32+
path: '/api/v0/bootstrap/list',
33+
handler: resources.bootstrap.list
34+
})
3335

34-
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
35-
api.route({
36-
method: 'GET',
37-
path: '/api/v0/bootstrap/rm',
38-
handler: resources.bootstrap.rm,
39-
config: {
40-
validate: {
41-
query: {
42-
arg: Joi.string().required(), // multiaddr to rm
43-
all: Joi.boolean()
36+
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
37+
api.route({
38+
method: 'GET',
39+
path: '/api/v0/bootstrap/rm',
40+
handler: resources.bootstrap.rm,
41+
config: {
42+
validate: {
43+
query: {
44+
arg: Joi.string().required(), // multiaddr to rm
45+
all: Joi.boolean()
46+
}
4447
}
4548
}
46-
}
47-
})
49+
})
50+
}

src/http-api/routes/config.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

4-
api.route({
5-
method: '*',
6-
path: '/api/v0/config/{key?}',
7-
config: {
8-
pre: [
9-
{ method: resources.config.getOrSet.parseArgs, assign: 'args' }
10-
],
11-
handler: resources.config.getOrSet.handler
12-
}
13-
})
3+
module.exports = (server) => {
4+
const api = server.select('API')
145

15-
api.route({
16-
method: '*',
17-
path: '/api/v0/config/show',
18-
handler: resources.config.show
19-
})
6+
api.route({
7+
method: '*',
8+
path: '/api/v0/config/{key?}',
9+
config: {
10+
pre: [
11+
{ method: resources.config.getOrSet.parseArgs, assign: 'args' }
12+
],
13+
handler: resources.config.getOrSet.handler
14+
}
15+
})
2016

21-
api.route({
22-
method: '*',
23-
path: '/api/v0/config/replace',
24-
config: {
25-
payload: {
26-
parse: false,
27-
output: 'stream'
28-
},
29-
pre: [
30-
{ method: resources.config.replace.parseArgs, assign: 'args' }
31-
],
32-
handler: resources.config.replace.handler
33-
}
34-
})
17+
api.route({
18+
method: '*',
19+
path: '/api/v0/config/show',
20+
handler: resources.config.show
21+
})
22+
23+
api.route({
24+
method: '*',
25+
path: '/api/v0/config/replace',
26+
config: {
27+
payload: {
28+
parse: false,
29+
output: 'stream'
30+
},
31+
pre: [
32+
{ method: resources.config.replace.parseArgs, assign: 'args' }
33+
],
34+
handler: resources.config.replace.handler
35+
}
36+
})
37+
}

src/http-api/routes/id.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

4-
api.route({
5-
method: 'GET',
6-
path: '/api/v0/id',
7-
handler: resources.id.get
8-
})
3+
module.exports = (server) => {
4+
const api = server.select('API')
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/id',
9+
handler: resources.id.get
10+
})
11+
}

src/http-api/routes/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
require('./version')
2-
require('./id')
3-
require('./bootstrap')
4-
// require('./block')
5-
// require('./object')
6-
// require('./repo')
7-
require('./config')
1+
module.exports = (server) => {
2+
require('./version')(server)
3+
require('./id')(server)
4+
require('./bootstrap')(server)
5+
// require('./block')(server)
6+
// require('./object')(server)
7+
// require('./repo')(server)
8+
require('./config')(server)
9+
}

src/http-api/routes/object.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

43
// TODO
4+
module.exports = (server) => {
5+
const api = server.select('API')
56

6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/object',
9-
handler: resources.object
10-
})
7+
api.route({
8+
method: 'GET',
9+
path: '/api/v0/object',
10+
handler: resources.object
11+
})
12+
}

src/http-api/routes/repo.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

43
// TODO
4+
module.exports = (server) => {
5+
const api = server.select('API')
56

6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/repo',
9-
handler: resources.repo
10-
})
7+
api.route({
8+
method: 'GET',
9+
path: '/api/v0/repo',
10+
handler: resources.repo
11+
})
12+
}

src/http-api/routes/version.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const api = require('./../index.js').server.select('API')
21
const resources = require('./../resources')
32

4-
api.route({
5-
method: 'GET',
6-
path: '/api/v0/version',
7-
handler: resources.version.get
8-
})
3+
module.exports = (server) => {
4+
const api = server.select('API')
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/version',
9+
handler: resources.version.get
10+
})
11+
}

0 commit comments

Comments
 (0)