Define your express routes as properties
express = require "express"
request = require "request"
app = express.createServer()
defaultResponse = (req,res,next) -> res.send req.originalUrl.substring(1)
app.get.propertyRoute = defaultResponse
app.get '/regularRoute', defaultResponse
app.all "/*", (req, res, next) ->
if r = (m = app[req.method.toLowerCase()])[req.originalUrl.substring(1)]
r.apply @, arguments
else
m req.originalUrl, arguments...
app.listen 8909
request {url: "http://localhost:8909/propertyRoute", method: 'GET'}, ->
console.log arguments[2]
request {url: "http://localhost:8909/regularRoute", method: 'GET'}, ->
console.log arguments[2]
results:
$ propertyRoute
$ regularRoute
Written by James Womack
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#