docpad-plugin-basicauth
v2.0.2
Published
express.basicAuth as a DocPad plugin.
Downloads
4
Maintainers
Readme
Express' basicAuth() as a DocPad plugin.
Setup
Add the protected route and user/pass info to the docpad.coffee configuration file like so:
express = require('express')
authMiddleware = express.basicAuth (user, pass) ->
return user is 'super' and pass is 'secret'
docpadConfig = {
plugins:
basicauth:
protectedPage: '/admin.html'
user: 'testUser'
pass: 'testPass'
events:
serverExtend: (opts) ->
docpad = @docpad
opts.serverExpress.use (req,res,next) =>
cleanUrl = req.url.replace(/\?.*/,'')
file = docpad.getFileByUrl(req.url) or docpad.getFileByUrl(cleanUrl)
return next() unless file?.get('protected')
return authMiddleware(req,res,next)
}
module.exports = docpadConfig
And that's it for now!