                     if req.username == 'anonymous' || !users[req.username] || req.authorization.basic.password != users[req.username].password
                         next(new restify.NotAuthorizedError())
                     else
-                    next()
+                        return next()
                 )
  
     head: (path, handlers...) ->


AddonHelper = require './AddonHelper'

Sys = require './addons/Sys/Sys'
Net = require './addons/Net/Net'

class SysAPI extends AddonHelper

    @include Sys
    @include Net
    
    constructor: (options) ->
        @server = new restify.createServer(options);
        @pre()

    connect: (port) ->
        @server.listen port, () ->
            console.log('API listening on port %d', port);
        
    auth: (options) ->
        options = options || {enabled:false}
        
        if options.enabled == true
            @server.use(restify.authorizationParser())

    post: (path, handlers...) ->
      @server.post(path, handlers)
     
    response: (req, res, next, x) ->
        response = {}
        
        if x.err? && x.err != ''   
            response.err = x.err
        else
            response.data = x
              
        res.send({ response: response });
        return next();
        

module.exports = API
