 # Return the host meta file
 # support only JSON format
 # @TODO : support xml
-module.exports.webfingerHostMeta = (req, res) ->
+module.exports.webfingerHostMeta = (req, res, next) ->
 
     return res.sendStatus 404 unless req.params.ext is 'json'
 

    res.header 'Access-Control-Allow-Methods', 'GET'

    CozyInstance.first (err, instance) ->
        return next err if err?
        unless instance?.domain
            return next new Error "Cozy's domain has not been registered"

        host = 'https://' + instance.domain
        template = "#{host}/webfinger/json?resource={uri}"

        hostmeta = links:
            rel: 'lrdd'

module.exports.webfingerAccount = (req, res, next) ->

    CozyInstance.first (err, instance) ->
        domain = instance?.domain or req.headers.host
        unless domain
            return next new Error "Cozy's domain has not been registered"
        host = "https://#{domain}"

        if req.params.module in ['caldav', 'carddav']
            routes = router.getRoutes()
            if routes['sync']?
