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

Commit

Permalink
Register routes on the injected server
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Mar 13, 2016
1 parent c46e055 commit 8e0cb1f
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.start = (callback) => {
server.connection({ host: gateway[2], port: gateway[4], labels: 'Gateway' })

// load routes
require('./routes')
require('./routes')(server)

server.start((err) => {
if (err) {
Expand Down
14 changes: 8 additions & 6 deletions src/http-api/routes/block.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO
module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
path: '/api/v0/block',
handler: resources.block
})
api.route({
method: 'GET',
path: '/api/v0/block',
handler: resources.block
})
}
77 changes: 40 additions & 37 deletions src/http-api/routes/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')
const Joi = require('joi')

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

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
api.route({
method: 'GET',
path: '/api/v0/bootstrap/add',
handler: resources.bootstrap.add,
config: {
validate: {
query: {
arg: Joi.string().required(), // multiaddr to add
default: Joi.boolean()
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L818
api.route({
method: 'GET',
path: '/api/v0/bootstrap',
handler: resources.bootstrap.list
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
api.route({
method: 'GET',
path: '/api/v0/bootstrap/add',
handler: resources.bootstrap.add,
config: {
validate: {
query: {
arg: Joi.string().required(), // multiaddr to add
default: Joi.boolean()
}
}
}
}
})
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
api.route({
method: 'GET',
path: '/api/v0/bootstrap/list',
handler: resources.bootstrap.list
})
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
api.route({
method: 'GET',
path: '/api/v0/bootstrap/list',
handler: resources.bootstrap.list
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
api.route({
method: 'GET',
path: '/api/v0/bootstrap/rm',
handler: resources.bootstrap.rm,
config: {
validate: {
query: {
arg: Joi.string().required(), // multiaddr to rm
all: Joi.boolean()
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
api.route({
method: 'GET',
path: '/api/v0/bootstrap/rm',
handler: resources.bootstrap.rm,
config: {
validate: {
query: {
arg: Joi.string().required(), // multiaddr to rm
all: Joi.boolean()
}
}
}
}
})
})
}
63 changes: 33 additions & 30 deletions src/http-api/routes/config.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

api.route({
method: '*',
path: '/api/v0/config/{key?}',
config: {
pre: [
{ method: resources.config.getOrSet.parseArgs, assign: 'args' }
],
handler: resources.config.getOrSet.handler
}
})
module.exports = (server) => {
const api = server.select('API')

api.route({
method: '*',
path: '/api/v0/config/show',
handler: resources.config.show
})
api.route({
method: '*',
path: '/api/v0/config/{key?}',
config: {
pre: [
{ method: resources.config.getOrSet.parseArgs, assign: 'args' }
],
handler: resources.config.getOrSet.handler
}
})

api.route({
method: '*',
path: '/api/v0/config/replace',
config: {
payload: {
parse: false,
output: 'stream'
},
pre: [
{ method: resources.config.replace.parseArgs, assign: 'args' }
],
handler: resources.config.replace.handler
}
})
api.route({
method: '*',
path: '/api/v0/config/show',
handler: resources.config.show
})

api.route({
method: '*',
path: '/api/v0/config/replace',
config: {
payload: {
parse: false,
output: 'stream'
},
pre: [
{ method: resources.config.replace.parseArgs, assign: 'args' }
],
handler: resources.config.replace.handler
}
})
}
15 changes: 9 additions & 6 deletions src/http-api/routes/id.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

api.route({
method: 'GET',
path: '/api/v0/id',
handler: resources.id.get
})
module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
path: '/api/v0/id',
handler: resources.id.get
})
}
16 changes: 9 additions & 7 deletions src/http-api/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require('./version')
require('./id')
require('./bootstrap')
// require('./block')
// require('./object')
// require('./repo')
require('./config')
module.exports = (server) => {
require('./version')(server)
require('./id')(server)
require('./bootstrap')(server)
// require('./block')(server)
// require('./object')(server)
// require('./repo')(server)
require('./config')(server)
}
14 changes: 8 additions & 6 deletions src/http-api/routes/object.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO
module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
path: '/api/v0/object',
handler: resources.object
})
api.route({
method: 'GET',
path: '/api/v0/object',
handler: resources.object
})
}
14 changes: 8 additions & 6 deletions src/http-api/routes/repo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO
module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
path: '/api/v0/repo',
handler: resources.repo
})
api.route({
method: 'GET',
path: '/api/v0/repo',
handler: resources.repo
})
}
15 changes: 9 additions & 6 deletions src/http-api/routes/version.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

api.route({
method: 'GET',
path: '/api/v0/version',
handler: resources.version.get
})
module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
path: '/api/v0/version',
handler: resources.version.get
})
}

0 comments on commit 8e0cb1f

Please sign in to comment.