Skip to content

Commit

Permalink
Merge pull request #366 from dadi/feature/allow-options-on-token-route
Browse files Browse the repository at this point in the history
feat: allow options request for token route
  • Loading branch information
jimlambie authored Dec 5, 2017
2 parents 54499f7 + 91a804a commit f3fb920
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 406 deletions.
12 changes: 12 additions & 0 deletions dadi/lib/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,19 @@ module.exports = function (server) {
var method = req.method && req.method.toLowerCase()
if (method === 'post') {
return tokens.generate(req, res, next)
} else if (method === 'options') {
res.statusCode = 200
res.setHeader('content-type', 'application/json')

if (config.get('cors') === true) {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS')
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization')
}

return res.end(JSON.stringify({}))
}

next()
})
}
15 changes: 7 additions & 8 deletions dadi/lib/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var _ = require('underscore')
var crypto = require('crypto')
var formatError = require('@dadi/format-error')
var fs = require('fs')
Expand Down Expand Up @@ -159,7 +158,7 @@ module.exports.transformQuery = function (obj, type, format) {
}

if (obj) {
Object.keys(obj).forEach((key) => {
Object.keys(obj).forEach(key => {
if ((typeof obj[key] === 'object') && (obj[key] !== null)) {
this.transformQuery(obj[key], type)
} else if (typeof obj[key] === 'string') {
Expand Down Expand Up @@ -233,7 +232,7 @@ module.exports.validateCollectionSchema = function (obj) {
response.errors.push({section: 'settings', message: 'must be provided'})
}

if (!_.isEmpty(response.errors)) {
if (response.errors.length > 0) {
response.success = false
return response
}
Expand Down Expand Up @@ -262,13 +261,13 @@ module.exports.validateCollectionSchema = function (obj) {
if (!obj.settings.index) {
indexSpecified = false
} else {
if (_.isArray(obj.settings.index)) {
_.each(obj.settings.index, (index) => {
if (_.contains(Object.keys(index.keys), obj.settings.sort)) {
if (Array.isArray(obj.settings.index)) {
obj.settings.index.forEach(index => {
if (Object.keys(index.keys).includes(obj.settings.sort)) {
indexSpecified = true
}
})
} else if (_.contains(Object.keys(obj.settings.index.keys), obj.settings.sort)) {
} else if (Object.keys(obj.settings.index.keys).includes(obj.settings.sort)) {
indexSpecified = true
}
}
Expand All @@ -278,7 +277,7 @@ module.exports.validateCollectionSchema = function (obj) {
}
}

response.success = _.isEmpty(response.errors)
response.success = response.errors.length === 0

return response
}
Expand Down
Loading

0 comments on commit f3fb920

Please sign in to comment.