Created
May 10, 2013 13:54
-
-
Save aventuralabs/5554537 to your computer and use it in GitHub Desktop.
Deferring body parser for photo uploads...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper function limitFileType | |
limitFileType = (part) -> | |
if !part.filename || part.filename.match /\.(jpg|jpeg|png|gif)$/i | |
@handlePart part | |
# helper function to process picture | |
uploadPicture = (req, res, next) -> | |
req.session.save (err) -> | |
req.session.progress ?= {} | |
req.session.progress['pic'] = -1 | |
if req.session.auth.loggedIn | |
userId = req.session.auth.userId | |
findUserById userId, (err, user) -> | |
if err | |
res.send 404 | |
else | |
req.user = user | |
photos.uploadPic req, res | |
else | |
res.send 404 | |
app.configure -> | |
# SETS | |
app.set 'port', process.env.PORT || 3000 | |
app.set 'views', __dirname + '/views' | |
app.set 'view engine', 'jade' | |
# BACKEND | |
app.use express.favicon() | |
app.use express.logger 'dev' | |
app.use express.limit '5mb' # THIS LIMITS YOUR FILE SIZE VIA EXPRESS | |
app.use express.methodOverride() | |
app.use express.cookieParser() | |
app.use connect.session { secret : 'your secret goes here' } | |
app.use express.bodyParser { defer : true, onPart : limitFileType } | |
app.use uploader { timeout : 30 } # WRITE A CUSTOM FORM HANDLER HERE | |
app.use '/pictures/upload', uploadPicture # inserted here due to integration problems between limit, defer and everyauth | |
# FRONTEND | |
app.use express.favicon 'public/favicon.ico' | |
app.use express.compress() | |
app.use stylus.middleware(...stylus details...) | |
app.use express.static path.join(__dirname, '/public') | |
app.use everyauth.middleware() | |
app.use app.router | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment