Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Update traceur and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoodman committed Jan 20, 2014
1 parent fd72c30 commit 85b8f28
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions middleware/subdomain.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
nconf = require("nconf")

host = nconf.get("host")
hostEsc = host.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
plunkRe = new RegExp("^([0-9a-zA-Z]+)\.plunk\.#{hostEsc}$")
previewRe = new RegExp("^([0-9a-zA-Z]+)\.#{hostEsc}$")
recapitalize = (id) ->
id.replace /([a-z]/, ""
module.exports.middleware = (config = {}) ->
(req, res, next) ->
# Rewrite plunk previews to the expected path
if matches = req.headers.host.match(plunkRe)
req.url = "/plunks/#{matches[1]}#{req.url}"
console.log "Rewrote url to", req.url
# Rewrite temporary previews to the expected path
else if matches = req.headers.host.match(previewRe)
req.url = "/#{matches[1]}#{req.url}"
console.log "Rewrote url to", req.url
next()

0 comments on commit 85b8f28

Please sign in to comment.