Create a gist now

Instantly share code, notes, and snippets.

@balupton /README.md
Last active Dec 11, 2015

DocPad: Protecting documents with basic http authentication
# Import
express = require('express')
# Create our auth middleware
authMiddleware = express.basicAuth (user, pass) ->
return user is 'super' and pass is 'secret'
# Configure DocPad
docpadConfig =
serverExtend: (opts) ->
# Prepare
docpad = @
# Define our own custom middleware to handle protected pages
opts.serverExpress.use (req,res,next) =>
# Prepare
cleanUrl = req.url.replace(/\?.*/,'')
file = docpad.getFileByUrl(req.url) or docpad.getFileByUrl(cleanUrl)
# Continue with the next middleware if the file doesn't exist or isn't protected
return next() unless file?.get('protected')
# The file is protected so lets forward the request onto our auth middleware
return authMiddleware(req,res,next)
# Export
module.exports = docpadConfig
title: "My protected document"
protected: true

Only make me available if the user has authetnicated themselve

@sergeylukin

You most likely meant

docpad = @docpad

instead of

docpad = @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment