Skip to content

Commit

Permalink
fix: Remove the unecessary check an a required value for the 'next' f…
Browse files Browse the repository at this point in the history
…unction in the 'app.route' argument
  • Loading branch information
nicolasdao committed Aug 29, 2017
1 parent 1e13fe8 commit ca60cf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ const app = () => {
route: (routeDetails) => {
if (!routeDetails)
throw new Error('Missing arg. \'routeDetails\' must be defined in function \'route\'.')
if (!routeDetails.next)
throw new Error('Missing \'next\' function. \'routeDetails.next\' must be defined in function \'route\'.')
if (typeof(routeDetails.next) != 'function')
if (routeDetails.next && typeof(routeDetails.next) != 'function')
throw new Error('\'next\' must be a function.')

const method = routeDetails.method ? routeDetails.method.trim().toUpperCase() : null
Expand Down
16 changes: 11 additions & 5 deletions src/webfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,20 @@ const handleHttpRequest = (req, res, appconfig) => Promise.resolve(appconfig ||
/**
* Returns a function (req, res) => ... that the Google Cloud Function expects.
*
* @param {function} httpNextRequest Callback function (req, res) => ... This gets executed after all the headers checks.
* @param {object} appconfig Optional configuration file. If it exists, it will override the appconfig.json file.
* @param {String|Function|Array|Object} arg1 Here what it means based on its type:
* - String: Route path (e.g. '/users/{userId}/account')
* - Function: Callback function (req, res) => ... This gets executed after all the headers checks.
* - Array: Array of endpoints (e.g. [app.get('/users', (req, res, params) => ...), app.post('/stories', (req, res, params) => ...)])
* - Object: Endpoint (e.g. app.get('/users', (req, res, params) => ...))
* @param {Function|Object} arg2 Here what it means based on its type:
* - Function: Callback function (req, res) => ... This gets executed after all the headers checks.
* - Object: appconfig. If it exists, it will override the appconfig.json file.
* @param {object} arg3 appconfig. If it exists, it will override the appconfig.json file.
* @return {function} (req, res) => ...
*/
//const serveHttp = (httpNextRequest, appconfig) => (req, res) => {
const serveHttp = (arg1, arg2, appconfig) => {
const serveHttp = (arg1, arg2, arg3) => {
const appConfigFile = getAppConfig() || {}
const appConfigArg = appconfig || {}
const appConfigArg = arg3 || {}
let _appconfig = null
let route = null
let httpNextRequest = null
Expand Down

0 comments on commit ca60cf1

Please sign in to comment.