Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am new to Express so I'd like to clear my code. This is Express with Redis support. I am getting someId and then I am searching it on Redis or using scraper which accepts this ID. I am then using just prepared template jade and rendering it.

exports.run = (req, res) ->
  return res.status(400).json(error: 'no someId') unless req.query.someId?

  orderId = req.query.someId
  redis.get someId, (err, response) ->
    if err?
      log.error config.redisErrorMessage if check err.message
      log.warn err, 'Error during redis.get'

    if response?
      res.setHeader('content-type', 'text/html')
      res.send response

    else
      scrapeData someId, res, (err, locals) ->
        if err?
          log.warn {err, orderId}, 'order not found'
          return res.status(404).json(error: err.message)

        if locals.redirect?
          return res.redirect 301, locals.redirectUrl

        res.app.render 'index', locals, (err, html) ->
          if err?
            log.warn err, 'render error'
            return res.status(404).json(error: err.message)

          else
            # render without waiting setex
            res.setHeader('content-type', 'text/html')
            res.send html

            # caching data after final render
            redis.setex orderId, config.REDIS_CACHE_INTERVAL, html, (err) ->
              if err?
                if check err.message
                  log.error err, config.redisErrorMessage
                else
                  log.error err, 'Error during redis.setex'
share|improve this question
    
So... no one can help? –  Jesus_Maria Sep 3 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.