Permalink
Browse files

Update traceur and other stuff

  • Loading branch information...
1 parent fd72c30 commit 85b8f28db2a2ac7f6269e8765f7b26046fea732c @ggoodman ggoodman committed Jan 20, 2014
Showing with 23 additions and 0 deletions.
  1. +23 −0 middleware/subdomain.coffee
@@ -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.