Skip to content

Instantly share code, notes, and snippets.

@tfechner
Forked from balupton/README.md
Created April 9, 2013 08:11
Show Gist options
  • Save tfechner/5343887 to your computer and use it in GitHub Desktop.
Save tfechner/5343887 to your computer and use it in GitHub Desktop.
# 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

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