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

Commit

Permalink
refactor: parse query strings in http-api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
niinpatel committed Apr 5, 2019
1 parent d5fa74e commit fb114f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/runtime/dns-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MAX_RECURSIVE_DEPTH = 32

module.exports = (domain, opts, callback) => {
// recursive is true by default, it's set to false only if explicitly passed as argument in opts
const recursive = opts.recursive == null || opts.recursive.toString() !== 'false'
const recursive = opts.recursive == null ? true : Boolean(opts.recursive)

let depth
if (recursive) {
Expand Down
8 changes: 7 additions & 1 deletion src/http/api/resources/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
const Boom = require('boom')

module.exports = async (request, h) => {
const { arg: domain, recursive, format } = request.query
const domain = request.query.arg

if (!domain) {
throw Boom.badRequest("Argument 'domain' is required")
}

const format = request.query.format

// query parameters are passed as strings and need to be parsed to expected type
let recursive = request.query.recursive || request.query.r
recursive = !(recursive && recursive === 'false')

const path = await request.server.app.ipfs.dns(domain, { recursive, format })
return h.response({
Path: path
Expand Down

0 comments on commit fb114f1

Please sign in to comment.