How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • const reactIntlLocaleMessages = function (req, res, next) {
        const accept = accepts(req);
        const locale = accept.language(languages) || "en";
        req.locale = locale;
        req.localeDataScript = getLocaleDataScript(locale);
        req.messages = getMessages(locale);
        next();
    };
    
    
    /Enalmada/next-reason-boilerplate MIT
  • var accepts = require('accepts')
    var http = require('http')
     
    function app (req, res) {
      var accept = accepts(req)
     
      // the order of this list is significant; should be server preferred order
    // the order of this list is significant; should be server preferred order
      switch (accept.type(['json', 'html'])) {
        case 'json':
          res.setHeader('Content-Type', 'application/json')
          res.write('{"hello":"world!"}')
          break
        case 'html':
          res.setHeader('Content-Type', 'text/html')
          res.write('<b>hello, world!</b>')
          break
        default:
          // the fallback is text/plain, so no need to specify it above
    // the fallback is text/plain, so no need to specify it above
          res.setHeader('Content-Type', 'text/plain')
          res.write('hello, world!')
          break
      }
     
      res.end()
    }
     
    http.createServer(app).listen(3000)
    Docs
  • function build (req) {
      
      //...
    req.accepts = function reqAccepts (...args) {
        const accept = accepts(this)
        return accept.types.apply(accept, args)
      }
    
      req.acceptsEncodings = function (...args) {
        const accept = accepts(this)
        return accept.encodings.apply(accept, args)
      }
    
      
    
      //...
    }
    
    /fyrejet/fyrejet MIT
  • 
          request(server3)
          .get('/index.js')
          .set('Accept-Encoding', 'gzip')
          .expect(200)
          .expect('Cache-Control', 'public, max-age=0')
          .expect('Content-Encoding', 'gzip')
          .expect('Content-Type', /javascript/)
          .expect('Content-Length', content.length)
          .expect('Vary', 'Accept-Encoding')
          .expect(index.toString())
          .end(function (err, res) {
            if (err)
              return done(err)
            res.should.have.header('Content-Length')
            res.should.have.header('Last-Modified')
            res.should.have.header('ETag')
    
            etag = res.headers.etag
    
            done()
          })
        
    /koajs/static-cache
  • const search = async (req, res, next) => {
    	
    	//...
    if (!(await fs.isDir(req.absolute))) return next()
    	if (accepts(req).type('html') !== 'html') return next() // todo: support JSON & plain text
    
    	let results = []
    	
    	//...
    }
    
    
    /derhuerst/casket ISC
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples