 CozyInstance = require '../models/instance'
+router = require '../lib/router'
 
 # Return the host meta file
 # support only JSON format

                        'auth-method': OAUTH_VERSION
                        'auth-endpoint': "#{host}/apps/remotestorage/oauth/"

                link.properties[OAUTH_VERSION] = link.properties['auth-endpoint']

                accountInfo.links.push link

            return res.send 200, accountInfo

    else
        res.send 404

# OpenID provider, public email, public tel, ...
module.exports.webfingerAccount = (req, res, next) ->

    CozyInstance.first (err, instance) ->
        return next err if err?
        return next new Error('no instance') unless instance?.domain

        host = "https://#{instance.domain}"
        if req.params.module in ['caldav', 'carddav']
            routes = router.getRoutes()
            if routes['sync']?
                res.redirect "#{host}/public/sync/"
            else
                res.send 404

        else if req.params.module is 'webfinger'

            OAUTH_VERSION = 'http://tools.ietf.org/html/rfc6749#section-4.2'
            PROTOCOL_VERSION = 'draft-dejong-remotestorage-01'

