diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serve.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js index 6a0bb88..75356a9 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -66,6 +66,25 @@ Serve.prototype.go = function () { var self = this this.res.setTimeout(0) + var conf = self.app.config.patchfoo || {} + var authtok = conf.auth || null + if (authtok) { + var auth = this.req.headers['authorization'] + var tok = null + //console.log('Authorization: ',auth) + + if (auth) { + var a = auth.split(' ') + if (a[0] == 'Basic') { + tok = Buffer.from(a[1],'base64').toString('ascii') + } + } + if (tok != authtok) { + self.res.writeHead(401, {'WWW-Authenticate': 'Basic realm="Patchfoo"'}) + self.res.end('Not authorized') + return + } + } if (this.req.method === 'POST' || this.req.method === 'PUT') { if (/^multipart\/form-data/.test(this.req.headers['content-type'])) { |