Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 419e916

Browse files
committed
Register routes on the injected connection
1 parent c46e055 commit 419e916

File tree

9 files changed

+114
-108
lines changed

9 files changed

+114
-108
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.select('API'))
5050

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

src/http-api/routes/block.js

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

43
// TODO
5-
6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/block',
9-
handler: resources.block
10-
})
4+
module.exports = (api) => {
5+
api.route({
6+
method: 'GET',
7+
path: '/api/v0/block',
8+
handler: resources.block
9+
})
10+
}

src/http-api/routes/bootstrap.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
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 = (api) => {
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+
})
1111

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()
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()
22+
}
2223
}
2324
}
24-
}
25-
})
25+
})
2626

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-
})
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+
})
3333

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()
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()
44+
}
4445
}
4546
}
46-
}
47-
})
47+
})
48+
}

src/http-api/routes/config.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
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 = (api) => {
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+
})
1414

15-
api.route({
16-
method: '*',
17-
path: '/api/v0/config/show',
18-
handler: resources.config.show
19-
})
15+
api.route({
16+
method: '*',
17+
path: '/api/v0/config/show',
18+
handler: resources.config.show
19+
})
2020

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-
})
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+
})
35+
}

src/http-api/routes/id.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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 = (api) => {
4+
api.route({
5+
method: 'GET',
6+
path: '/api/v0/id',
7+
handler: resources.id.get
8+
})
9+
}

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 = (api) => {
2+
require('./version')(api)
3+
require('./id')(api)
4+
require('./bootstrap')(api)
5+
// require('./block')(api)
6+
// require('./object')(api)
7+
// require('./repo')(api)
8+
require('./config')(api)
9+
}

src/http-api/routes/object.js

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

43
// TODO
5-
6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/object',
9-
handler: resources.object
10-
})
4+
module.exports = (api) => {
5+
api.route({
6+
method: 'GET',
7+
path: '/api/v0/object',
8+
handler: resources.object
9+
})
10+
}

src/http-api/routes/repo.js

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

43
// TODO
5-
6-
api.route({
7-
method: 'GET',
8-
path: '/api/v0/repo',
9-
handler: resources.repo
10-
})
4+
module.exports = (api) => {
5+
api.route({
6+
method: 'GET',
7+
path: '/api/v0/repo',
8+
handler: resources.repo
9+
})
10+
}

src/http-api/routes/version.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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 = (api) => {
4+
api.route({
5+
method: 'GET',
6+
path: '/api/v0/version',
7+
handler: resources.version.get
8+
})
9+
}

0 commit comments

Comments
 (0)