File size: 135,701 Bytes
16356ef | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | {"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar escapeHtml = require('escape-html')\nvar express = require('../../lib/express');\n\nvar verbose = process.env.NODE_ENV !== 'test'\n\nvar app = module.exports = express();\n\napp.map = function(a, route){\n route = route || '';\n for (var key in a) {\n switch (typeof a[key]) {\n // { '/path': { ... }}\n case 'object':\n app.map(a[key], route + key);\n break;\n // get: function(){ ... }\n case 'function':\n if (verbose) console.log('%s %s', k", "suffix": " },\n\n delete: function(req, res){\n res.send('delete users');\n }\n};\n\nvar pets = {\n list: function(req, res){\n res.send('user ' + escapeHtml(req.params.uid) + '\\'s pets')\n },\n\n delete: function(req, res){\n res.send('delete ' + escapeHtml(req.pa", "middle": "ey, route);\n app[key](route, a[key]);\n break;\n }\n }\n};\n\nvar users = {\n list: function(req, res){\n res.send('user list');\n },\n\n get: function(req, res){\n res.send('user ' + escapeHtml(req.params.uid))\n ", "meta": {"filepath": "examples/route-map/index.js", "language": "javascript", "file_size": 1419, "cut_index": 524, "middle_length": 229}}
{"prefix": "trict'\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../..');\nvar path = require('node:path');\nvar app = express();\nvar logger = require('morgan');\nvar cookieParser = require('cookie-parser');\nvar methodOverride = require('method-override');\nvar site = require('./site');\nvar post = require('./post');\nvar user = require('./user');\n\nmodule.exports = app;\n\n// Config\n\napp.set('view engine', 'ejs');\napp.set('views', path.join(__dirname, 'views'));\n\n/* istanbul ignore next */\nif (!module.parent) {\n ap", "suffix": "\n\n// User\n\napp.get('/users', user.list);\napp.all('/user/:id{/:op}', user.load);\napp.get('/user/:id', user.view);\napp.get('/user/:id/view', user.view);\napp.get('/user/:id/edit', user.edit);\napp.put('/user/:id/edit', user.update);\n\n// Posts\n\napp.get('/posts'", "middle": "p.use(logger('dev'));\n}\n\napp.use(methodOverride('_method'));\napp.use(cookieParser());\napp.use(express.urlencoded({ extended: true }))\napp.use(express.static(path.join(__dirname, 'public')));\n\n// General\n\napp.get('/', site.index);", "meta": {"filepath": "examples/route-separation/index.js", "language": "javascript", "file_size": 1136, "cut_index": 518, "middle_length": 229}}
{"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../..');\nvar logger = require('morgan');\nvar path = require('node:path');\nvar app = express();\n\n// log requests\napp.use(logger('dev'));\n\n// express on its own has no notion\n// of a \"file\". The express.static()\n// middleware checks for a file matching\n// the `req.path` within the directory\n// that you pass it. In this case \"GET /js/app.js\"\n// will look for \"./public/js/app.js\".\n\napp.use(express.static(path.join(__dirname, 'public')));\n\n// if you wante", "suffix": "dleware,\n// thus it serves the file correctly by ignoring \"/static\"\napp.use('/static', express.static(path.join(__dirname, 'public')));\n\n// if for some reason you want to serve files from\n// several directories, you can use express.static()\n// multiple tim", "middle": "d to \"prefix\" you may use\n// the mounting feature of Connect, for example\n// \"GET /static/js/app.js\" instead of \"GET /js/app.js\".\n// The mount-path \"/static\" is simply removed before\n// passing control to the express.static() mid", "meta": {"filepath": "examples/static-files/index.js", "language": "javascript", "file_size": 1363, "cut_index": 524, "middle_length": 229}}
{"prefix": "express = require('../../..');\nvar fs = require('node:fs');\nvar path = require('node:path');\n\nmodule.exports = function(parent, options){\n var dir = path.join(__dirname, '..', 'controllers');\n var verbose = options.verbose;\n fs.readdirSync(dir).forEach(function(name){\n var file = path.join(dir, name)\n if (!fs.statSync(file).isDirectory()) return;\n verbose && console.log('\\n %s:', name);\n var obj = require(file);\n var name = obj.name || name;\n var prefix = obj.prefix || '';\n var app", "suffix": "ews'));\n\n // generate routes based\n // on the exported methods\n for (var key in obj) {\n // \"reserved\" exports\n if (~['name', 'prefix', 'engine', 'before'].indexOf(key)) continue;\n // route exports\n switch (key) {\n case '", "middle": " = express();\n var handler;\n var method;\n var url;\n\n // allow specifying the view engine\n if (obj.engine) app.set('view engine', obj.engine);\n app.set('views', path.join(__dirname, '..', 'controllers', name, 'vi", "meta": {"filepath": "examples/mvc/lib/boot.js", "language": "javascript", "file_size": 2263, "cut_index": 563, "middle_length": 229}}
{"prefix": "trict'\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../../');\nvar path = require('node:path');\n\nvar app = module.exports = express();\n\n// path to where the files are stored on disk\nvar FILES_DIR = path.join(__dirname, 'files')\n\napp.get('/', function(req, res){\n res.send('<ul>' +\n '<li>Download <a href=\"/files/notes/groceries.txt\">notes/groceries.txt</a>.</li>' +\n '<li>Download <a href=\"/files/amazing.txt\">amazing.txt</a>.</li>' +\n '<li>Download <a href=\"/files/missing.txt\">missing.txt<", "suffix": "t) {\n res.download(req.params.file.join('/'), { root: FILES_DIR }, function (err) {\n if (!err) return; // file sent\n if (err.status !== 404) return next(err); // non-404 error\n // file for download not found\n res.statusCode = 404;\n res.send", "middle": "/a>.</li>' +\n '<li>Download <a href=\"/files/CCTV大赛上海分赛区.txt\">CCTV大赛上海分赛区.txt</a>.</li>' +\n '</ul>')\n});\n\n// /files/* is accessed via req.params[0]\n// but here we name it :file\napp.get('/files/*file', function (req, res, nex", "meta": {"filepath": "examples/downloads/index.js", "language": "javascript", "file_size": 1193, "cut_index": 518, "middle_length": 229}}
{"prefix": "redis first:\n// https://redis.io/\n\n// then:\n// $ npm install redis\n// $ redis-server\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../..');\nvar path = require('node:path');\nvar redis = require('redis');\n\nvar db = redis.createClient();\nvar app = express();\n\napp.use(express.static(path.join(__dirname, 'public')));\n\n// npm install redis\n\n/**\n * Redis Initialization\n */\n\nasync function initializeRedis() {\n try {\n // connect to Redis\n\n await db.connect();\n\n // populate search\n\n await db.s", "suffix": ", err);\n process.exit(1);\n }\n}\n\n/**\n * GET search for :query.\n */\n\napp.get('/search/{:query}', function (req, res, next) {\n var query = req.params.query || '';\n db.sMembers(query)\n .then((vals) => res.send(vals))\n .catch((err) => {\n consol", "middle": "Add('ferret', 'tobi');\n await db.sAdd('ferret', 'loki');\n await db.sAdd('ferret', 'jane');\n await db.sAdd('cat', 'manny');\n await db.sAdd('cat', 'luna');\n } catch (err) {\n console.error('Error initializing Redis:'", "meta": {"filepath": "examples/search/index.js", "language": "javascript", "file_size": 1577, "cut_index": 537, "middle_length": 229}}
{"prefix": "trict'\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../../');\nvar GithubView = require('./github-view');\nvar md = require('marked').parse;\n\nvar app = module.exports = express();\n\n// register .md as an engine in express view system\napp.engine('md', function(str, options, fn){\n try {\n var html = md(str);\n html = html.replace(/\\{([^}]+)\\}/g, function(_, name){\n return options[name] || '';\n });\n fn(null, html);\n } catch(err) {\n fn(err);\n }\n});\n\n// pointing to a particular gith", "suffix": "res.locals, and locals passed\n // work like they normally would\n res.render('examples/markdown/views/index.md', { title: 'Example' });\n});\n\napp.get('/Readme.md', function(req, res){\n // rendering a view from https://github.com/expressjs/express/blob/mas", "middle": "ub repo to load files from it\napp.set('views', 'expressjs/express');\n\n// register a new view constructor\napp.set('view', GithubView);\n\napp.get('/', function(req, res){\n // rendering a view relative to the repo.\n // app.locals, ", "meta": {"filepath": "examples/view-constructor/index.js", "language": "javascript", "file_size": 1167, "cut_index": 518, "middle_length": 229}}
{"prefix": "ht(c) 2014-2015 Douglas Christopher Wilson\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module dependencies.\n * @private\n */\n\nvar debug = require('debug')('express:view');\nvar path = require('node:path');\nvar fs = require('node:fs');\n\n/**\n * Module variables.\n * @private\n */\n\nvar dirname = path.dirname;\nvar basename = path.basename;\nvar extname = path.extname;\nvar join = path.join;\nvar resolve = path.resolve;\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = View;\n\n/**\n * Initialize a new `View` with t", "suffix": "ions\n * @public\n */\n\nfunction View(name, options) {\n var opts = options || {};\n\n this.defaultEngine = opts.defaultEngine;\n this.ext = extname(name);\n this.name = name;\n this.root = opts.root;\n\n if (!this.ext && !this.defaultEngine) {\n throw new Er", "middle": "he given `name`.\n *\n * Options:\n *\n * - `defaultEngine` the default template engine name\n * - `engines` template engine require() cache\n * - `root` root path for view lookup\n *\n * @param {string} name\n * @param {object} opt", "meta": {"filepath": "lib/view.js", "language": "javascript", "file_size": 3809, "cut_index": 614, "middle_length": 229}}
{"prefix": " = require('node:assert')\nvar express = require('../')\n\ndescribe('app', function(){\n describe('.locals', function () {\n it('should default object with null prototype', function () {\n var app = express()\n assert.ok(app.locals)\n assert.strictEqual(typeof app.locals, 'object')\n assert.strictEqual(Object.getPrototypeOf(app.locals), null)\n })\n\n describe('.settings', function () {\n it('should contain app settings ', function () {\n var app = express()\n app.set('titl", "suffix": "\n assert.ok(app.locals.settings)\n assert.strictEqual(typeof app.locals.settings, 'object')\n assert.strictEqual(app.locals.settings, app.settings)\n assert.strictEqual(app.locals.settings.title, 'Express')\n })\n })\n })\n})\n", "middle": "e', 'Express')", "meta": {"filepath": "test/app.locals.js", "language": "javascript", "file_size": 806, "cut_index": 536, "middle_length": 14}}
{"prefix": "\n\nvar assert = require('node:assert')\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('app', function(){\n describe('.VERB()', function(){\n it('should not get invoked without error handler on error', function(done) {\n var app = express();\n\n app.use(function(req, res, next){\n next(new Error('boom!'))\n });\n\n app.get('/bar', function(req, res){\n res.send('hello, world!');\n });\n\n request(app)\n .post('/bar')\n .expect(500, /Error:", "suffix": "ar d = false;\n\n app.get('/', function(req, res, next){\n next(new Error('fabricated error'));\n }, function(req, res, next) {\n a = true;\n next();\n }, function(err, req, res, next){\n b = true;\n assert.strictEq", "middle": " boom!/, done);\n });\n\n it('should only call an error handling routing callback when an error is propagated', function(done){\n var app = express();\n\n var a = false;\n var b = false;\n var c = false;\n v", "meta": {"filepath": "test/app.routes.error.js", "language": "javascript", "file_size": 1504, "cut_index": 524, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('req', function(){\n describe('.accepts(type)', function(){\n it('should return true when Accept is not present', function(done){\n var app = express();\n\n app.use(function(req, res, next){\n res.end(req.accepts('json') ? 'yes' : 'no');\n });\n\n request(app)\n .get('/')\n .expect('yes', done);\n })\n\n it('should return true when present', function(done){\n var app = express();\n\n app.use(function(req, res, next){\n res.e", "suffix": "app = express();\n\n app.use(function(req, res, next){\n res.end(req.accepts('json') ? 'yes' : 'no');\n });\n\n request(app)\n .get('/')\n .set('Accept', 'text/html')\n .expect('no', done);\n })\n })\n\n it('should accept an ar", "middle": "nd(req.accepts('json') ? 'yes' : 'no');\n });\n\n request(app)\n .get('/')\n .set('Accept', 'application/json')\n .expect('yes', done);\n })\n\n it('should return false otherwise', function(done){\n var ", "meta": {"filepath": "test/req.accepts.js", "language": "javascript", "file_size": 2964, "cut_index": 563, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('req', function(){\n describe('.protocol', function(){\n it('should return the protocol string', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.protocol);\n });\n\n request(app)\n .get('/')\n .expect('http', done);\n })\n\n describe('when \"trust proxy\" is enabled', function(){\n it('should respect X-Forwarded-Proto', function(done){\n var app = express();\n\n app.enable('trust proxy');", "suffix": "ult to the socket addr if X-Forwarded-Proto not present', function(done){\n var app = express();\n\n app.enable('trust proxy');\n\n app.use(function(req, res){\n req.socket.encrypted = true;\n res.end(req.protocol);\n ", "middle": "\n\n app.use(function(req, res){\n res.end(req.protocol);\n });\n\n request(app)\n .get('/')\n .set('X-Forwarded-Proto', 'https')\n .expect('https', done);\n })\n\n it('should defa", "meta": {"filepath": "test/req.protocol.js", "language": "javascript", "file_size": 2579, "cut_index": 563, "middle_length": 229}}
{"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../../');\nvar logger = require('morgan');\nvar app = module.exports = express();\nvar test = app.get('env') === 'test'\n\nif (!test) app.use(logger('dev'));\n\n// error handling middleware have an arity of 4\n// instead of the typical (req, res, next),\n// otherwise they behave exactly like regular\n// middleware, you may have several of them,\n// in different orders etc.\n\nfunction error(err, req, res, next) {\n // log it\n if (!test) console.error(err.stack);", "suffix": "');\n});\n\napp.get('/next', function(req, res, next){\n // We can also pass exceptions to next()\n // The reason for process.nextTick() is to show that\n // next() can be called inside an async operation,\n // in real life it can be a DB read or HTTP request", "middle": "\n\n // respond with 500 \"Internal Server Error\".\n res.status(500);\n res.send('Internal Server Error');\n}\n\napp.get('/', function () {\n // Caught and passed down to the errorHandler middleware\n throw new Error('something broke!", "meta": {"filepath": "examples/error/index.js", "language": "javascript", "file_size": 1333, "cut_index": 524, "middle_length": 229}}
{"prefix": "'use strict'\n\n// Fake user database\n\nvar users = [\n { name: 'TJ', email: 'tj@vision-media.ca' },\n { name: 'Tobi', email: 'tobi@vision-media.ca' }\n];\n\nexports.list = function(req, res){\n res.render('users', { title: 'Users', users: users });\n};\n\nexports.load = function(req, res, next){\n var id = req.params.id;\n req.user = users[id];\n if (req.user) {\n next();\n } else {\n var err = new Error('cannot find user ' + id);\n err.status = 404;\n next(err);\n }\n};\n\nexports.view = function(req, res){\n ", "suffix": " });\n};\n\nexports.update = function(req, res){\n // Normally you would handle all kinds of\n // validation and save back to the db\n var user = req.body.user;\n req.user.name = user.name;\n req.user.email = user.email;\n res.redirect(req.get('Referrer') || ", "middle": " res.render('users/view', {\n title: 'Viewing user ' + req.user.name,\n user: req.user\n });\n};\n\nexports.edit = function(req, res){\n res.render('users/edit', {\n title: 'Editing user ' + req.user.name,\n user: req.user\n ", "meta": {"filepath": "examples/route-separation/user.js", "language": "javascript", "file_size": 1006, "cut_index": 512, "middle_length": 229}}
{"prefix": "use strict'\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../..');\nvar logger = require('morgan');\nvar vhost = require('vhost');\n\n/*\nedit /etc/hosts:\n\n127.0.0.1 foo.example.com\n127.0.0.1 bar.example.com\n127.0.0.1 example.com\n*/\n\n// Main server app\n\nvar main = express();\n\nif (!module.parent) main.use(logger('dev'));\n\nmain.get('/', function(req, res){\n res.send('Hello from main app!');\n});\n\nmain.get('/:sub', function(req, res){\n res.send('requested ' + req.params.sub);\n});\n\n// R", "suffix": "ss();\n\napp.use(vhost('*.example.com', redirect)); // Serves all subdomains via Redirect app\napp.use(vhost('example.com', main)); // Serves top level domain via Main server app\n\n/* istanbul ignore next */\nif (!module.parent) {\n app.listen(3000);\n console.", "middle": "edirect app\n\nvar redirect = express();\n\nredirect.use(function(req, res){\n if (!module.parent) console.log(req.vhost);\n res.redirect('http://example.com:3000/' + req.vhost[0]);\n});\n\n// Vhost app\n\nvar app = module.exports = expre", "meta": {"filepath": "examples/vhost/index.js", "language": "javascript", "file_size": 1037, "cut_index": 513, "middle_length": 229}}
{"prefix": "express = require('../../');\n\nvar app = module.exports = express();\n\n// Ad-hoc example resource method\n\napp.resource = function(path, obj) {\n this.get(path, obj.index);\n this.get(path + '/:a..:b{.:format}', function(req, res){\n var a = parseInt(req.params.a, 10);\n var b = parseInt(req.params.b, 10);\n var format = req.params.format;\n obj.range(req, res, a, b, format);\n });\n this.get(path + '/:id', obj.show);\n this.delete(path + '/:id', function(req, res){\n var id = parseInt(req.params.id,", "suffix": "er.\n\nvar User = {\n index: function(req, res){\n res.send(users);\n },\n show: function(req, res){\n res.send(users[req.params.id] || { error: 'Cannot find user' });\n },\n destroy: function(req, res, id){\n var destroyed = id in users;\n delete us", "middle": " 10);\n obj.destroy(req, res, id);\n });\n};\n\n// Fake records\n\nvar users = [\n { name: 'tj' }\n , { name: 'ciaran' }\n , { name: 'aaron' }\n , { name: 'guillermo' }\n , { name: 'simon' }\n , { name: 'tobi' }\n];\n\n// Fake controll", "meta": {"filepath": "examples/resource/index.js", "language": "javascript", "file_size": 2295, "cut_index": 563, "middle_length": 229}}
{"prefix": "express = require('../..');\nvar logger = require('morgan');\nvar path = require('node:path');\nvar session = require('express-session');\nvar methodOverride = require('method-override');\n\nvar app = module.exports = express();\n\n// set our default template engine to \"ejs\"\n// which prevents the need for using file extensions\napp.set('view engine', 'ejs');\n\n// set views for error and 404 pages\napp.set('views', path.join(__dirname, 'views'));\n\n// define a custom res.message() method\n// which stores messages in the ", "suffix": "ssages.push(msg);\n return this;\n};\n\n// log\nif (!module.parent) app.use(logger('dev'));\n\n// serve static files\napp.use(express.static(path.join(__dirname, 'public')));\n\n// session support\napp.use(session({\n resave: false, // don't save session if unmodifi", "middle": "session\napp.response.message = function(msg){\n // reference `req.session` via the `this.req` reference\n var sess = this.req.session;\n // simply add the msg to an array for later\n sess.messages = sess.messages || [];\n sess.me", "meta": {"filepath": "examples/mvc/index.js", "language": "javascript", "file_size": 2320, "cut_index": 563, "middle_length": 229}}
{"prefix": "'use strict'\n\nvar express = require('../../');\nvar app = module.exports = express();\nvar users = require('./db');\n\n// so either you can deal with different types of formatting\n// for expected response in index.js\napp.get('/', function(req, res){\n res.format({\n html: function(){\n res.send('<ul>' + users.map(function(user){\n return '<li>' + user.name + '</li>';\n }).join('') + '</ul>');\n },\n\n text: function(){\n res.send(users.map(function(user){\n return ' - ' + user.name ", "suffix": "tion format(path) {\n var obj = require(path);\n return function(req, res){\n res.format(obj);\n };\n}\n\napp.get('/users', format('./users'));\n\n/* istanbul ignore next */\nif (!module.parent) {\n app.listen(3000);\n console.log('Express started on port 3000", "middle": "+ '\\n';\n }).join(''));\n },\n\n json: function(){\n res.json(users);\n }\n });\n});\n\n// or you could write a tiny middleware like\n// this to add a layer of abstraction\n// and make things a bit more declarative:\n\nfunc", "meta": {"filepath": "examples/content-negotiation/index.js", "language": "javascript", "file_size": 1003, "cut_index": 512, "middle_length": 229}}
{"prefix": "var db = require('../../db');\n\nexports.engine = 'hbs';\n\nexports.before = function(req, res, next){\n var id = req.params.user_id;\n if (!id) return next();\n // pretend to query a database...\n process.nextTick(function(){\n req.user = db.users[id];\n // cant find that user\n if (!req.user) return next('route');\n // found it, move on to the routes\n next();\n });\n};\n\nexports.list = function(req, res, next){\n res.render('list', { users: db.users });\n};\n\nexports.edit = function(req, res, next){\n ", "suffix": "show = function(req, res, next){\n res.render('show', { user: req.user });\n};\n\nexports.update = function(req, res, next){\n var body = req.body;\n req.user.name = body.user.name;\n res.message('Information updated!');\n res.redirect('/user/' + req.user.id)", "middle": "res.render('edit', { user: req.user });\n};\n\nexports.", "meta": {"filepath": "examples/mvc/controllers/user/index.js", "language": "javascript", "file_size": 872, "cut_index": 559, "middle_length": 52}}
{"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar createError = require('http-errors')\nvar express = require('../../');\nvar app = module.exports = express();\n\n// Faux database\n\nvar users = [\n { name: 'tj' }\n , { name: 'tobi' }\n , { name: 'loki' }\n , { name: 'jane' }\n , { name: 'bandit' }\n];\n\n// Convert :to and :from to integers\n\napp.param(['to', 'from'], function(req, res, next, num, name){\n req.params[name] = parseInt(num, 10);\n if( isNaN(req.params[name]) ){\n next(createError(400, 'failed to parseInt '+num", "suffix": "**\n * GET index.\n */\n\napp.get('/', function(req, res){\n res.send('Visit /user/0 or /users/0-2');\n});\n\n/**\n * GET :user.\n */\n\napp.get('/user/:user', function (req, res) {\n res.send('user ' + req.user.name);\n});\n\n/**\n * GET users :from - :to.\n */\n\napp.get(", "middle": "));\n } else {\n next();\n }\n});\n\n// Load user by id\n\napp.param('user', function(req, res, next, id){\n req.user = users[id]\n if (req.user) {\n next();\n } else {\n next(createError(404, 'failed to find user'));\n }\n});\n\n/", "meta": {"filepath": "examples/params/index.js", "language": "javascript", "file_size": 1353, "cut_index": 524, "middle_length": 229}}
{"prefix": "express = require('../../');\nvar path = require('node:path');\nvar app = module.exports = express();\nvar logger = require('morgan');\nvar silent = process.env.NODE_ENV === 'test'\n\n// general config\napp.set('views', path.join(__dirname, 'views'));\napp.set('view engine', 'ejs');\n\n// our custom \"verbose errors\" setting\n// which we can use in the templates\n// via settings['verbose errors']\napp.enable('verbose errors');\n\n// disable them in production\n// use $ NODE_ENV=production node examples/error-pages\nif (app.s", "suffix": "404 since no other middleware\n // will match /404 after this one, and we're not\n // responding here\n next();\n});\n\napp.get('/403', function(req, res, next){\n // trigger a 403 error\n var err = new Error('not allowed!');\n err.status = 403;\n next(err);\n", "middle": "ettings.env === 'production') app.disable('verbose errors')\n\nsilent || app.use(logger('dev'));\n\n// Routes\n\napp.get('/', function(req, res){\n res.render('index.ejs');\n});\n\napp.get('/404', function(req, res, next){\n // trigger a ", "meta": {"filepath": "examples/error-pages/index.js", "language": "javascript", "file_size": 2665, "cut_index": 563, "middle_length": 229}}
{"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../../');\nvar path = require('node:path');\n\nvar app = module.exports = express();\n\n// Register ejs as .html. If we did\n// not call this, we would need to\n// name our views foo.ejs instead\n// of foo.html. The __express method\n// is simply a function that engines\n// use to hook into the Express view\n// system by default, so if we want\n// to change \"foo.ejs\" to \"foo.html\"\n// we simply pass _any_ function, in this\n// case `ejs.__express`.\n\napp.engine('.h", "suffix": "thout this you would need to\n// supply the extension to res.render()\n// ex: res.render('users.html').\napp.set('view engine', 'html');\n\n// Placeholder users\nvar users = [\n { name: 'tobi', email: 'tobi@learnboost.com' },\n { name: 'loki', email: 'loki@learn", "middle": "tml', require('ejs').__express);\n\n// Optional since express defaults to CWD/views\n\napp.set('views', path.join(__dirname, 'views'));\n\n// Path to our public directory\n\napp.use(express.static(path.join(__dirname, 'public')));\n\n// Wi", "meta": {"filepath": "examples/ejs/index.js", "language": "javascript", "file_size": 1331, "cut_index": 524, "middle_length": 229}}
{"prefix": "rts = express();\n\n// create an error with .status. we\n// can then use the property in our\n// custom error handler (Connect respects this prop as well)\n\nfunction error(status, msg) {\n var err = new Error(msg);\n err.status = status;\n return err;\n}\n\n// if we wanted to supply more than JSON, we could\n// use something similar to the content-negotiation\n// example.\n\n// here we validate the API key,\n// by mounting this middleware to /api\n// meaning only paths prefixed with \"/api\"\n// will cause this middleware t", "suffix": "turn next(error(401, 'invalid api key'))\n\n // all good, store req.key for route access\n req.key = key;\n next();\n});\n\n// map of valid api keys, typically mapped to\n// account info with some sort of database like redis.\n// api keys do _not_ serve as authe", "middle": "o be invoked\n\napp.use('/api', function(req, res, next){\n var key = req.query['api-key'];\n\n // key isn't present\n if (!key) return next(error(400, 'api key required'));\n\n // key is invalid\n if (apiKeys.indexOf(key) === -1) re", "meta": {"filepath": "examples/web-service/index.js", "language": "javascript", "file_size": 3044, "cut_index": 614, "middle_length": 229}}
{"prefix": "l redis first:\n// https://redis.io/\n\n// then:\n// $ npm install redis\n// $ redis-server\n\nvar express = require('../..');\nvar session = require('express-session');\n\nvar app = express();\n\n// Populates req.session\napp.use(session({\n resave: false, // don't save session if unmodified\n saveUninitialized: false, // don't create session until something stored\n secret: 'keyboard cat'\n}));\n\napp.get('/', function(req, res){\n var body = '';\n if (req.session.views) {\n ++req.session.views;\n } else {\n req.sess", "suffix": "view this page in several browsers :)</p>';\n }\n res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');\n});\n\n/* istanbul ignore next */\nif (!module.parent) {\n app.listen(3000);\n console.log('Express started on port 3000');\n}", "middle": "ion.views = 1;\n body += '<p>First time visiting? ", "meta": {"filepath": "examples/session/index.js", "language": "javascript", "file_size": 844, "cut_index": 535, "middle_length": 52}}
{"prefix": "df2-password')()\nvar path = require('node:path');\nvar session = require('express-session');\n\nvar app = module.exports = express();\n\n// config\n\napp.set('view engine', 'ejs');\napp.set('views', path.join(__dirname, 'views'));\n\n// middleware\n\napp.use(express.urlencoded())\napp.use(session({\n resave: false, // don't save session if unmodified\n saveUninitialized: false, // don't create session until something stored\n secret: 'shhhh, very secret'\n}));\n\n// Session-persisted message middleware\n\napp.use(function(re", "suffix": "</p>';\n if (msg) res.locals.message = '<p class=\"msg success\">' + msg + '</p>';\n next();\n});\n\n// placeholder database\n\nvar users = {\n tj: { name: 'tj' }\n};\n\n// when you create a user, generate a salt\n// and hash the password ('foobar' is the pass here)\n", "middle": "q, res, next){\n var err = req.session.error;\n var msg = req.session.success;\n delete req.session.error;\n delete req.session.success;\n res.locals.message = '';\n if (err) res.locals.message = '<p class=\"msg error\">' + err + '", "meta": {"filepath": "examples/auth/index.js", "language": "javascript", "file_size": 3570, "cut_index": 614, "middle_length": 229}}
{"prefix": "../..');\nvar logger = require('morgan');\nvar session = require('express-session');\n\n// pass the express to the connect redis module\n// allowing it to inherit from session.Store\nvar RedisStore = require('connect-redis')(session);\n\nvar app = express();\n\napp.use(logger('dev'));\n\n// Populates req.session\napp.use(session({\n resave: false, // don't save session if unmodified\n saveUninitialized: false, // don't create session until something stored\n secret: 'keyboard cat',\n store: new RedisStore\n}));\n\napp.get(", "suffix": "session.views) {\n ++req.session.views;\n } else {\n req.session.views = 1;\n body += '<p>First time visiting? view this page in several browsers :)</p>';\n }\n res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');\n});\n\n", "middle": "'/', function(req, res){\n var body = '';\n if (req.", "meta": {"filepath": "examples/session/redis.js", "language": "javascript", "file_size": 957, "cut_index": 582, "middle_length": 52}}
{"prefix": "express = require('../../lib/express');\n\nvar app = express();\n\n// Example requests:\n// curl http://localhost:3000/user/0\n// curl http://localhost:3000/user/0/edit\n// curl http://localhost:3000/user/1\n// curl http://localhost:3000/user/1/edit (unauthorized since this is not you)\n// curl -X DELETE http://localhost:3000/user/0 (unauthorized since you are not an admin)\n\n// Placeholder users\nvar users = [\n { id: 0, name: 'tj', email: 'tj@vision-media.ca', role: 'member' }\n , { id: 1, name: ", "suffix": " user = users[req.params.id];\n if (user) {\n req.user = user;\n next();\n } else {\n next(new Error('Failed to load user ' + req.params.id));\n }\n}\n\nfunction andRestrictToSelf(req, res, next) {\n // If our authenticated user is the user we are viewi", "middle": "'ciaran', email: 'ciaranj@gmail.com', role: 'member' }\n , { id: 2, name: 'aaron', email: 'aaron.heckmann+github@gmail.com', role: 'admin' }\n];\n\nfunction loadUser(req, res, next) {\n // You would fetch your user from the db\n var", "meta": {"filepath": "examples/route-middleware/index.js", "language": "javascript", "file_size": 2399, "cut_index": 563, "middle_length": 229}}
{"prefix": "\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../../');\nvar app = module.exports = express();\nvar logger = require('morgan');\nvar cookieParser = require('cookie-parser');\n\n// custom log format\nif (process.env.NODE_ENV !== 'test') app.use(logger(':method :url'))\n\n// parses request cookies, populating\n// req.cookies and req.signedCookies\n// when the secret is passed, used\n// for signing the cookies.\napp.use(cookieParser('my secret here'));\n\n// parses x-www-form-urlencoded\napp.use(express.urlencode", "suffix": "checkbox\" name=\"remember\"/> remember me</label> '\n + '<input type=\"submit\" value=\"Submit\"/>.</p></form>');\n }\n});\n\napp.get('/forget', function(req, res){\n res.clearCookie('remember');\n res.redirect(req.get('Referrer') || '/');\n});\n\napp.post('/', fu", "middle": "d())\n\napp.get('/', function(req, res){\n if (req.cookies.remember) {\n res.send('Remembered :). Click to <a href=\"/forget\">forget</a>!.');\n } else {\n res.send('<form method=\"post\"><p>Check to <label>'\n + '<input type=\"", "meta": {"filepath": "examples/cookies/index.js", "language": "javascript", "file_size": 1311, "cut_index": 524, "middle_length": 229}}
{"prefix": "e strict'\n\n/**\n * Module dependencies.\n */\n\nvar https = require('node:https');\nvar path = require('node:path');\nvar extname = path.extname;\n\n/**\n * Expose `GithubView`.\n */\n\nmodule.exports = GithubView;\n\n/**\n * Custom view that fetches and renders\n * remove github templates. You could\n * render templates from a database etc.\n */\n\nfunction GithubView(name, options){\n this.name = name;\n options = options || {};\n this.engine = options.engines[extname(name)];\n // \"root\" is the app.set('views') setting, howe", "suffix": "{\n host: 'raw.githubusercontent.com',\n port: 443,\n path: this.path,\n method: 'GET'\n };\n\n https.request(opts, function(res) {\n var buf = '';\n res.setEncoding('utf8');\n res.on('data', function(str){ buf += str });\n res.on('end', fun", "middle": "ver\n // in your own implementation you could ignore this\n this.path = '/' + options.root + '/master/' + name;\n}\n\n/**\n * Render the view.\n */\n\nGithubView.prototype.render = function(options, fn){\n var self = this;\n var opts = ", "meta": {"filepath": "examples/view-constructor/github-view.js", "language": "javascript", "file_size": 1069, "cut_index": 515, "middle_length": 229}}
{"prefix": "'use strict'\n\n/**\n * Module dependencies.\n */\n\nvar escapeHtml = require('escape-html');\nvar express = require('../..');\nvar fs = require('node:fs');\nvar marked = require('marked');\nvar path = require('node:path');\n\nvar app = module.exports = express();\n\n// register .md as an engine in express view system\n\napp.engine('md', function(path, options, fn){\n fs.readFile(path, 'utf8', function(err, str){\n if (err) return fn(err);\n var html = marked.parse(str).replace(/\\{([^}]+)\\}/g, function(_, name){\n ", "suffix": "q, res){\n res.render('index', { title: 'Markdown Example' });\n});\n\napp.get('/fail', function(req, res){\n res.render('missing', { title: 'Markdown Example' });\n});\n\n/* istanbul ignore next */\nif (!module.parent) {\n app.listen(3000);\n console.log('Expres", "middle": "return escapeHtml(options[name] || '');\n });\n fn(null, html);\n });\n});\n\napp.set('views', path.join(__dirname, 'views'));\n\n// make it the default, so we don't need .md\napp.set('view engine', 'md');\n\napp.get('/', function(re", "meta": {"filepath": "examples/markdown/index.js", "language": "javascript", "file_size": 1025, "cut_index": 512, "middle_length": 229}}
{"prefix": "e:path');\nvar User = require('./user');\nvar app = express();\n\napp.set('views', path.join(__dirname, 'views'));\napp.set('view engine', 'ejs');\n\n// filter ferrets only\n\nfunction ferrets(user) {\n return user.species === 'ferret'\n}\n\n// naive nesting approach,\n// delegating errors to next(err)\n// in order to expose the \"count\"\n// and \"users\" locals\n\napp.get('/', function(req, res, next){\n User.count(function(err, count){\n if (err) return next(err);\n User.all(function(err, users){\n if (err) return ne", "suffix": "able\n// on the request object\n\nfunction count(req, res, next) {\n User.count(function(err, count){\n if (err) return next(err);\n req.count = count;\n next();\n })\n}\n\nfunction users(req, res, next) {\n User.all(function(err, users){\n if (err) retu", "middle": "xt(err);\n res.render('index', {\n title: 'Users',\n count: count,\n users: users.filter(ferrets)\n });\n })\n })\n});\n\n\n\n\n// this approach is cleaner,\n// less nesting and we have\n// the variables avail", "meta": {"filepath": "examples/view-locals/index.js", "language": "javascript", "file_size": 3127, "cut_index": 614, "middle_length": 229}}
{"prefix": "./utils').methods;\nvar compileETag = require('./utils').compileETag;\nvar compileQueryParser = require('./utils').compileQueryParser;\nvar compileTrust = require('./utils').compileTrust;\nvar resolve = require('node:path').resolve;\nvar once = require('once')\nvar Router = require('router');\n\n/**\n * Module variables.\n * @private\n */\n\nvar slice = Array.prototype.slice;\nvar flatten = Array.prototype.flat;\n\n/**\n * Application prototype.\n */\n\nvar app = exports = module.exports = {};\n\n/**\n * Variable for trust proxy ", "suffix": "tion methods\n *\n * @private\n */\n\napp.init = function init() {\n var router = null;\n\n this.cache = Object.create(null);\n this.engines = Object.create(null);\n this.settings = Object.create(null);\n\n this.defaultConfiguration();\n\n // Setup getting to lazi", "middle": "inheritance back-compat\n * @private\n */\n\nvar trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';\n\n/**\n * Initialize the server.\n *\n * - setup default configuration\n * - setup default middleware\n * - setup route reflec", "meta": {"filepath": "lib/application.js", "language": "javascript", "file_size": 13977, "cut_index": 921, "middle_length": 229}}
{"prefix": " require('range-parser');\nvar parse = require('parseurl');\nvar proxyaddr = require('proxy-addr');\n\n/**\n * Request prototype.\n * @public\n */\n\nvar req = Object.create(http.IncomingMessage.prototype)\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = req\n\n/**\n * Return request header.\n *\n * The `Referrer` header field is special-cased,\n * both `Referrer` and `Referer` are interchangeable.\n *\n * Examples:\n *\n * req.get('Content-Type');\n * // => \"text/plain\"\n *\n * req.get('content-type');\n * ", "suffix": "e) {\n throw new TypeError('name argument is required to req.get');\n }\n\n if (typeof name !== 'string') {\n throw new TypeError('name must be a string to req.get');\n }\n\n var lc = name.toLowerCase();\n\n switch (lc) {\n case 'referer':\n case 'ref", "middle": " // => \"text/plain\"\n *\n * req.get('Something');\n * // => undefined\n *\n * Aliased as `req.header()`.\n *\n * @param {String} name\n * @return {String}\n * @public\n */\n\nreq.get =\nreq.header = function header(name) {\n if (!nam", "meta": {"filepath": "lib/request.js", "language": "javascript", "file_size": 12254, "cut_index": 921, "middle_length": 229}}
{"prefix": "ODS } = require('node:http');\nvar contentType = require('content-type');\nvar etag = require('etag');\nvar mime = require('mime-types')\nvar proxyaddr = require('proxy-addr');\nvar qs = require('qs');\nvar querystring = require('node:querystring');\nconst { Buffer } = require('node:buffer');\n\n\n/**\n * A list of lowercased HTTP methods that are supported by Node.js.\n * @api private\n */\nexports.methods = METHODS.map((method) => method.toLowerCase());\n\n/**\n * Return strong ETag for `body`.\n *\n * @param {String|Buffer", "suffix": "]\n * @return {String}\n * @api private\n */\n\nexports.wetag = createETagGenerator({ weak: true })\n\n/**\n * Normalize the given `type`, for example \"html\" becomes \"text/html\".\n *\n * @param {String} type\n * @return {Object}\n * @api private\n */\n\nexports.normalize", "middle": "} body\n * @param {String} [encoding]\n * @return {String}\n * @api private\n */\n\nexports.etag = createETagGenerator({ weak: false })\n\n/**\n * Return weak ETag for `body`.\n *\n * @param {String|Buffer} body\n * @param {String} [encoding", "meta": {"filepath": "lib/utils.js", "language": "javascript", "file_size": 5293, "cut_index": 716, "middle_length": 229}}
{"prefix": "'use strict'\n\n// install redis first:\n// https://redis.io/\n\n// then:\n// $ npm install redis online\n// $ redis-server\n\n/**\n * Module dependencies.\n */\n\nvar express = require('../..');\nvar online = require('online');\nvar redis = require('redis');\nvar db = redis.createClient();\n\n// online\n\nonline = online(db);\n\n// app\n\nvar app = express();\n\n// activity tracking, in this case using\n// the UA string, you would use req.user.id etc\n\napp.use(function(req, res, next){\n // fire-and-forget\n online.add(req.headers['u", "suffix": "req, res, next){\n online.last(5, function(err, ids){\n if (err) return next(err);\n res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));\n });\n});\n\n/* istanbul ignore next */\nif (!module.parent) {\n app.listen(3000);\n console.log('Express", "middle": "ser-agent']);\n next();\n});\n\n/**\n * List helper.\n */\n\nfunction list(ids) {\n return '<ul>' + ids.map(function(id){\n return '<li>' + id + '</li>';\n }).join('') + '</ul>';\n}\n\n/**\n * GET users online.\n */\n\napp.get('/', function(", "meta": {"filepath": "examples/online/index.js", "language": "javascript", "file_size": 1024, "cut_index": 512, "middle_length": 229}}
{"prefix": "('./utils').setCharset;\nvar cookie = require('cookie');\nvar send = require('send');\nvar extname = path.extname;\nvar resolve = path.resolve;\nvar vary = require('vary');\nconst { Buffer } = require('node:buffer');\n\n/**\n * Response prototype.\n * @public\n */\n\nvar res = Object.create(http.ServerResponse.prototype)\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = res\n\n/**\n * Set the HTTP status code for the response.\n *\n * Expects an integer value between 100 and 999 inclusive.\n * Throws an error if the pr", "suffix": "code` is not an integer.\n * @throws {RangeError} If `code` is outside the range 100 to 999.\n * @public\n */\n\nres.status = function status(code) {\n // Check if the status code is not an integer\n if (!Number.isInteger(code)) {\n throw new TypeError(`Inval", "middle": "ovided status code is not an integer or if it's outside the allowable range.\n *\n * @param {number} code - The HTTP status code to set.\n * @return {ServerResponse} - Returns itself for chaining methods.\n * @throws {TypeError} If `", "meta": {"filepath": "lib/response.js", "language": "javascript", "file_size": 24844, "cut_index": 1331, "middle_length": 229}}
{"prefix": "ht(c) 2009-2013 TJ Holowaychuk\n * Copyright(c) 2013 Roman Shtylman\n * Copyright(c) 2014-2015 Douglas Christopher Wilson\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module dependencies.\n */\n\nvar bodyParser = require('body-parser')\nvar EventEmitter = require('node:events').EventEmitter;\nvar mixin = require('merge-descriptors');\nvar proto = require('./application');\nvar Router = require('router');\nvar req = require('./request');\nvar res = require('./response');\n\n/**\n * Expose `createApplication()`.\n */\n\nexports", "suffix": "\n\n mixin(app, EventEmitter.prototype, false);\n mixin(app, proto, false);\n\n // expose the prototype that will get set on requests\n app.request = Object.create(req, {\n app: { configurable: true, enumerable: true, writable: true, value: app }\n })\n\n /", "middle": " = module.exports = createApplication;\n\n/**\n * Create an express application.\n *\n * @return {Function}\n * @api public\n */\n\nfunction createApplication() {\n var app = function(req, res, next) {\n app.handle(req, res, next);\n };", "meta": {"filepath": "lib/express.js", "language": "javascript", "file_size": 1636, "cut_index": 537, "middle_length": 229}}
{"prefix": "tion(){\n it('should work without handlers', function(done) {\n var req = { method: 'GET', url: '/' }\n var route = new Route('/foo')\n route.dispatch(req, {}, done)\n })\n\n it('should not stack overflow with a large sync stack', function (done) {\n this.timeout(5000) // long-running test\n\n var req = { method: 'GET', url: '/' }\n var route = new Route('/foo')\n\n route.get(function (req, res, next) {\n req.counter = 0\n next()\n })\n\n for (var i = 0; i < 6000; i++) {\n route.al", "suffix": " return done(err)\n assert.ok(req.called)\n assert.strictEqual(req.counter, 6000)\n done()\n })\n })\n\n describe('.all', function(){\n it('should add handler', function(done){\n var req = { method: 'GET', url: '/' };\n var route = n", "middle": "l(function (req, res, next) {\n req.counter++\n next()\n })\n }\n\n route.get(function (req, res, next) {\n req.called = true\n next()\n })\n\n route.dispatch(req, {}, function (err) {\n if (err)", "meta": {"filepath": "test/Route.js", "language": "javascript", "file_size": 6480, "cut_index": 716, "middle_length": 229}}
{"prefix": "sert(typeof router.handle === 'function')\n assert(typeof router.use === 'function')\n });\n\n it('should support .use of other routers', function (done) {\n var router = new Router();\n var another = new Router();\n\n another.get('/bar', function (req, res) {\n res.end();\n });\n router.use('/foo', another);\n\n router.handle({ url: '/foo/bar', method: 'GET' }, { end: done }, function () { });\n });\n\n it('should support dynamic routes', function (done) {\n var router = new Router();\n v", "suffix": "od: 'GET' }, { end: done }, function () { });\n });\n\n it('should handle blank URL', function (done) {\n var router = new Router();\n\n router.use(function (req, res) {\n throw new Error('should not be called')\n });\n\n router.handle({ url: '', ", "middle": "ar another = new Router();\n\n another.get('/:bar', function (req, res) {\n assert.strictEqual(req.params.bar, 'route')\n res.end();\n });\n router.use('/:foo', another);\n\n router.handle({ url: '/test/route', meth", "meta": {"filepath": "test/Router.js", "language": "javascript", "file_size": 17372, "cut_index": 921, "middle_length": 229}}
{"prefix": "\n\nvar express = require('../');\nvar request = require('supertest');\nvar assert = require('node:assert');\n\ndescribe('HEAD', function(){\n it('should default to GET', function(done){\n var app = express();\n\n app.get('/tobi', function(req, res){\n // send() detects HEAD\n res.send('tobi');\n });\n\n request(app)\n .head('/tobi')\n .expect(200, done);\n })\n\n it('should output the same headers as GET requests', function(done){\n var app = express();\n\n app.get('/tobi', function(req, res)", "suffix": "get('/tobi')\n .expect(200, function(err, res){\n if (err) return done(err);\n delete headers.date;\n delete res.headers.date;\n assert.deepEqual(res.headers, headers);\n done();\n });\n });\n })\n})\n\ndescribe('app.he", "middle": "{\n // send() detects HEAD\n res.send('tobi');\n });\n\n request(app)\n .head('/tobi')\n .expect(200, function(err, res){\n if (err) return done(err);\n var headers = res.headers;\n request(app)\n .", "meta": {"filepath": "test/app.head.js", "language": "javascript", "file_size": 1412, "cut_index": 524, "middle_length": 229}}
{"prefix": "ar express = require('..')\nvar request = require('supertest')\n\ndescribe('app', function(){\n it('should inherit from event emitter', function(done){\n var app = express();\n app.on('foo', done);\n app.emit('foo');\n })\n\n it('should be callable', function(){\n var app = express();\n assert.equal(typeof app, 'function');\n })\n\n it('should 404 without routes', function(done){\n request(express())\n .get('/')\n .expect(404, done);\n })\n})\n\ndescribe('app.parent', function(){\n it('should return", "suffix": "sert.strictEqual(blog.parent, app)\n assert.strictEqual(blogAdmin.parent, blog)\n })\n})\n\ndescribe('app.mountpath', function(){\n it('should return the mounted path', function(){\n var admin = express();\n var app = express();\n var blog = express()", "middle": " the parent when mounted', function(){\n var app = express()\n , blog = express()\n , blogAdmin = express();\n\n app.use('/blog', blog);\n blog.use('/admin', blogAdmin);\n\n assert(!app.parent, 'app.parent');\n as", "meta": {"filepath": "test/app.js", "language": "javascript", "file_size": 2738, "cut_index": 563, "middle_length": 229}}
{"prefix": "se strict'\n\nvar after = require('after')\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('app.all()', function(){\n it('should add a router per method', function(done){\n var app = express();\n var cb = after(2, done)\n\n app.all('/tobi', function(req, res){\n res.end(req.method);\n });\n\n request(app)\n .put('/tobi')\n .expect(200, 'PUT', cb)\n\n request(app)\n .get('/tobi')\n .expect(200, 'GET', cb)\n })\n\n it('should run the callback for a method j", "suffix": "ction(done){\n var app = express()\n , n = 0;\n\n app.all('/*splat', function(req, res, next){\n if (n++) return done(new Error('DELETE called several times'));\n next();\n });\n\n request(app)\n .del('/tobi')\n .expect(404, done);\n ", "middle": "ust once', fun", "meta": {"filepath": "test/app.all.js", "language": "javascript", "file_size": 790, "cut_index": 514, "middle_length": 14}}
{"prefix": " = require('../')\nvar assert = require('node:assert')\n\ndescribe('app.listen()', function(){\n it('should wrap with an HTTP server', function(done){\n var app = express();\n\n var server = app.listen(0, function () {\n server.close(done)\n });\n })\n it('should callback on HTTP server errors', function (done) {\n var app1 = express()\n var app2 = express()\n\n var server1 = app1.listen(0, function (err) {\n assert(!err)\n app2.listen(server1.address().port, function (err) {\n asse", "suffix": ".1', 5, function () {\n const { address, port } = server.address();\n assert.strictEqual(address, '127.0.0.1');\n assert(Number.isInteger(port) && port > 0);\n // backlog isn’t directly inspectable, but if no error was thrown\n // we kn", "middle": "rt(err.code === 'EADDRINUSE')\n server1.close()\n done()\n })\n })\n })\n it('accepts port + hostname + backlog + callback', function (done) {\n const app = express();\n const server = app.listen(0, '127.0.0", "meta": {"filepath": "test/app.listen.js", "language": "javascript", "file_size": 1713, "cut_index": 537, "middle_length": 229}}
{"prefix": "ar express = require('../')\n , fs = require('node:fs');\nvar path = require('node:path')\n\nfunction render(path, options, fn) {\n fs.readFile(path, 'utf8', function(err, str){\n if (err) return fn(err);\n str = str.replace('{{user.name}}', options.user.name);\n fn(null, str);\n });\n}\n\ndescribe('app', function(){\n describe('.engine(ext, fn)', function(){\n it('should map a template engine', function(done){\n var app = express();\n\n app.set('views', path.join(__dirname, 'fixtures'))\n app.", "suffix": "})\n\n it('should throw when the callback is missing', function(){\n var app = express();\n assert.throws(function () {\n app.engine('.html', null);\n }, /callback function required/)\n })\n\n it('should work without leading \".\"', fun", "middle": "engine('.html', render);\n app.locals.user = { name: 'tobi' };\n\n app.render('user.html', function(err, str){\n if (err) return done(err);\n assert.strictEqual(str, '<p>tobi</p>')\n done();\n })\n ", "meta": {"filepath": "test/app.engine.js", "language": "javascript", "file_size": 2246, "cut_index": 563, "middle_length": 229}}
{"prefix": " var app = express();\n\n app.param(['id', 'uid'], function(req, res, next, id){\n id = Number(id);\n if (isNaN(id)) return next('route');\n req.params.id = id;\n next();\n });\n\n app.get('/post/:id', function(req, res){\n var id = req.params.id;\n res.send((typeof id) + ':' + id)\n });\n\n app.get('/user/:uid', function(req, res){\n var id = req.params.id;\n res.send((typeof id) + ':' + id)\n });\n\n request(app)\n .get('/user/1", "suffix": "name, fn)', function(){\n it('should map logic for a single param', function(done){\n var app = express();\n\n app.param('id', function(req, res, next, id){\n id = Number(id);\n if (isNaN(id)) return next('route');\n req.params.i", "middle": "23')\n .expect(200, 'number:123', function (err) {\n if (err) return done(err)\n request(app)\n .get('/post/123')\n .expect('number:123', done)\n })\n })\n })\n\n describe('.param(", "meta": {"filepath": "test/app.param.js", "language": "javascript", "file_size": 7560, "cut_index": 716, "middle_length": 229}}
{"prefix": "pl'), function (err, str) {\n if (err) return done(err);\n assert.strictEqual(str, '<p>tobi</p>')\n done();\n })\n })\n\n it('should support absolute paths with \"view engine\"', function(done){\n var app = createApp();\n\n app.set('view engine', 'tmpl');\n app.locals.user = { name: 'tobi' };\n\n app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) {\n if (err) return done(err);\n assert.strictEqual(str, '<p>tobi</p>')\n done();\n ", "suffix": "ion (err, str) {\n if (err) return done(err);\n assert.strictEqual(str, '<p>tobi</p>')\n done();\n })\n })\n\n it('should support index.<engine>', function(done){\n var app = createApp();\n\n app.set('views', path.join(__dir", "middle": " })\n })\n\n it('should expose app.locals', function(done){\n var app = createApp();\n\n app.set('views', path.join(__dirname, 'fixtures'))\n app.locals.user = { name: 'tobi' };\n\n app.render('user.tmpl', funct", "meta": {"filepath": "test/app.render.js", "language": "javascript", "file_size": 11092, "cut_index": 921, "middle_length": 229}}
{"prefix": " function(){\n it('should return a new route', function(done){\n var app = express();\n\n app.route('/foo')\n .get(function(req, res) {\n res.send('get');\n })\n .post(function(req, res) {\n res.send('post');\n });\n\n request(app)\n .post('/foo')\n .expect('post', done);\n });\n\n it('should all .VERB after .all', function(done){\n var app = express();\n\n app.route('/foo')\n .all(function(req, res, next) {\n next();\n })\n .get(function(req, res) {\n res.send('get')", "suffix": ".route('/:foo')\n .get(function(req, res) {\n res.send(req.params.foo);\n });\n\n request(app)\n .get('/test')\n .expect('test', done);\n });\n\n it('should not error on empty routes', function(done){\n var app = express();\n\n app.route('/:", "middle": ";\n })\n .post(function(req, res) {\n res.send('post');\n });\n\n request(app)\n .post('/foo')\n .expect('post', done);\n });\n\n it('should support dynamic routes', function(done){\n var app = express();\n\n app", "meta": {"filepath": "test/app.route.js", "language": "javascript", "file_size": 4762, "cut_index": 614, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('OPTIONS', function(){\n it('should default to the routes defined', function(done){\n var app = express();\n\n app.post('/', function(){});\n app.get('/users', function(req, res){});\n app.put('/users', function(req, res){});\n\n request(app)\n .options('/users')\n .expect('Allow', 'GET, HEAD, PUT')\n .expect(200, 'GET, HEAD, PUT', done);\n })\n\n it('should only include each method once', function(done){\n var app = express();\n\n app.delete('/', functi", "suffix": "expect(200, 'GET, HEAD, PUT', done);\n })\n\n it('should not be affected by app.all', function(done){\n var app = express();\n\n app.get('/', function(){});\n app.get('/users', function(req, res){});\n app.put('/users', function(req, res){});\n app", "middle": "on(){});\n app.get('/users', function(req, res){});\n app.put('/users', function(req, res){});\n app.get('/users', function(req, res){});\n\n request(app)\n .options('/users')\n .expect('Allow', 'GET, HEAD, PUT')\n .", "meta": {"filepath": "test/app.options.js", "language": "javascript", "file_size": 2845, "cut_index": 563, "middle_length": 229}}
{"prefix": "ess = require('../')\n , request = require('supertest');\n\ndescribe('app', function(){\n describe('.response', function(){\n it('should extend the response prototype', function(done){\n var app = express();\n\n app.response.shout = function(str){\n this.send(str.toUpperCase());\n };\n\n app.use(function(req, res){\n res.shout('hey');\n });\n\n request(app)\n .get('/')\n .expect('HEY', done);\n })\n\n it('should only extend for the referenced app', function (done)", "suffix": "res.shout('foo')\n })\n\n app2.get('/', function (req, res) {\n res.shout('foo')\n })\n\n request(app1)\n .get('/')\n .expect(200, 'FOO', cb)\n\n request(app2)\n .get('/')\n .expect(500, /(?:not a function|has", "middle": " {\n var app1 = express()\n var app2 = express()\n var cb = after(2, done)\n\n app1.response.shout = function (str) {\n this.send(str.toUpperCase())\n }\n\n app1.get('/', function (req, res) {\n ", "meta": {"filepath": "test/app.response.js", "language": "javascript", "file_size": 2973, "cut_index": 563, "middle_length": 229}}
{"prefix": " .get('/user/1')\n .expect('x-router', 'undefined')\n .expect('x-user-id', '1')\n .expect(200, '1', done);\n })\n\n describe('methods', function () {\n methods.forEach(function (method) {\n if (method === 'connect') return;\n\n it('should include ' + method.toUpperCase(), function (done) {\n if (method === 'query' && shouldSkipQuery(process.versions.node)) {\n this.skip()\n }\n var app = express();\n\n app[method]('/foo', function (req, res) {\n r", "suffix": "s(app[method].bind(app, '/', 3), /argument handler must be a function/);\n })\n });\n\n it('should re-route when method is altered', function (done) {\n var app = express();\n var cb = after(3, done);\n\n app.use(function (req, res, next)", "middle": "es.send(method)\n });\n\n request(app)\n [method]('/foo')\n .expect(200, done)\n })\n\n it('should reject numbers for app.' + method, function () {\n var app = express();\n assert.throw", "meta": {"filepath": "test/app.router.js", "language": "javascript", "file_size": 29831, "cut_index": 1331, "middle_length": 229}}
{"prefix": "ess = require('../')\n , request = require('supertest');\n\ndescribe('app', function(){\n describe('.request', function(){\n it('should extend the request prototype', function(done){\n var app = express();\n\n app.request.querystring = function(){\n return require('node:url').parse(this.url).query;\n };\n\n app.use(function(req, res){\n res.end(req.querystring());\n });\n\n request(app)\n .get('/foo?name=tobi')\n .expect('name=tobi', done);\n })\n\n it('should onl", "suffix": " function (req, res) {\n res.send(req.foobar())\n })\n\n app2.get('/', function (req, res) {\n res.send(req.foobar())\n })\n\n request(app1)\n .get('/')\n .expect(200, 'tobi', cb)\n\n request(app2)\n .get('/')", "middle": "y extend for the referenced app', function (done) {\n var app1 = express()\n var app2 = express()\n var cb = after(2, done)\n\n app1.request.foobar = function () {\n return 'tobi'\n }\n\n app1.get('/',", "meta": {"filepath": "test/app.request.js", "language": "javascript", "file_size": 2983, "cut_index": 563, "middle_length": 229}}
{"prefix": "p = express();\n app.set('foo', 'bar');\n assert.equal(app.get('foo'), 'bar');\n })\n\n it('should set prototype values', function () {\n var app = express()\n app.set('hasOwnProperty', 42)\n assert.strictEqual(app.get('hasOwnProperty'), 42)\n })\n\n it('should return the app', function () {\n var app = express();\n assert.equal(app.set('foo', 'bar'), app);\n })\n\n it('should return the app when undefined', function () {\n var app = express();\n assert.equal(app", "suffix": "or prototype values', function () {\n var app = express()\n assert.strictEqual(app.set('hasOwnProperty'), undefined)\n })\n\n describe('\"etag\"', function(){\n it('should throw on bad value', function(){\n var app = express();\n a", "middle": ".set('foo', undefined), app);\n })\n\n it('should return set value', function () {\n var app = express()\n app.set('foo', 'bar')\n assert.strictEqual(app.set('foo'), 'bar')\n })\n\n it('should return undefined f", "meta": {"filepath": "test/config.js", "language": "javascript", "file_size": 5823, "cut_index": 716, "middle_length": 229}}
{"prefix": "nt-Type', 'application/json')\n .set('Transfer-Encoding', 'chunked')\n .expect(200, '{}', done)\n })\n\n it('should handle no message-body', function (done) {\n request(createApp())\n .post('/')\n .set('Content-Type', 'application/json')\n .unset('Transfer-Encoding')\n .expect(200, '{}', done)\n })\n\n // The old node error message modification in body parser is catching this\n it('should 400 when only whitespace', function (done) {\n request(createApp())\n .post('/')\n .se", "suffix": "app.use(function (req, res, next) {\n req.headers['content-length'] = '20' // bad length\n next()\n })\n\n app.use(express.json())\n\n app.post('/', function (req, res) {\n res.json(req.body)\n })\n\n request(app)\n .post('/')\n ", "middle": "t('Content-Type', 'application/json')\n .send(' \\n')\n .expect(400, '[entity.parse.failed] ' + parseError(' \\n'), done)\n })\n\n it('should 400 when invalid content-length', function (done) {\n var app = express()\n\n ", "meta": {"filepath": "test/express.json.js", "language": "javascript", "file_size": 23675, "cut_index": 1331, "middle_length": 229}}
{"prefix": "/)\n })\n\n it('should serve static files', function (done) {\n request(this.app)\n .get('/todo.txt')\n .expect(200, '- groceries', done)\n })\n\n it('should support nesting', function (done) {\n request(this.app)\n .get('/users/tobi.txt')\n .expect(200, 'ferret', done)\n })\n\n it('should set Content-Type', function (done) {\n request(this.app)\n .get('/todo.txt')\n .expect('Content-Type', 'text/plain; charset=utf-8')\n .expect(200, done)\n }", "suffix": " function (done) {\n request(this.app)\n .get('/todo.txt')\n .expect('Cache-Control', 'public, max-age=0')\n .expect(200, done)\n })\n\n it('should support urlencoded pathnames', function (done) {\n request(this.app)\n .g", "middle": ")\n\n it('should set Last-Modified', function (done) {\n request(this.app)\n .get('/todo.txt')\n .expect('Last-Modified', /\\d{2} \\w{3} \\d{4}/)\n .expect(200, done)\n })\n\n it('should default max-age=0',", "meta": {"filepath": "test/express.static.js", "language": "javascript", "file_size": 23498, "cut_index": 1331, "middle_length": 229}}
{"prefix": "p.post('/', function (req, res) {\n res.json(req.body)\n })\n\n request(app)\n .post('/')\n .set('Content-Type', 'application/x-www-form-urlencoded')\n .send('str=')\n .expect(400, /content length/, done)\n })\n\n it('should handle Content-Length: 0', function (done) {\n request(this.app)\n .post('/')\n .set('Content-Type', 'application/x-www-form-urlencoded')\n .set('Content-Length', '0')\n .send('')\n .expect(200, '{}', done)\n })\n\n it('should handle empty mess", "suffix": "'{}', done)\n })\n\n it('should handle duplicated middleware', function (done) {\n var app = express()\n\n app.use(express.urlencoded())\n app.use(express.urlencoded())\n\n app.post('/', function (req, res) {\n res.json(req.body)\n })\n\n reque", "middle": "age-body', function (done) {\n request(createApp({ limit: '1kb' }))\n .post('/')\n .set('Content-Type', 'application/x-www-form-urlencoded')\n .set('Transfer-Encoding', 'chunked')\n .send('')\n .expect(200, ", "meta": {"filepath": "test/express.urlencoded.js", "language": "javascript", "file_size": 26741, "cut_index": 1331, "middle_length": 229}}
{"prefix": "be('.use(app)', function(){\n it('should mount the app', function(done){\n var blog = express()\n , app = express();\n\n blog.get('/blog', function(req, res){\n res.end('blog');\n });\n\n app.use(blog);\n\n request(app)\n .get('/blog')\n .expect('blog', done);\n })\n\n it('should support mount-points', function(done){\n var blog = express()\n , forum = express()\n , app = express();\n var cb = after(2, done)\n\n blog.get('/', function(req, res", "suffix": ".expect(200, 'blog', cb)\n\n request(app)\n .get('/forum')\n .expect(200, 'forum', cb)\n })\n\n it('should set the child\\'s .parent', function(){\n var blog = express()\n , app = express();\n\n app.use('/blog', blog);\n a", "middle": "){\n res.end('blog');\n });\n\n forum.get('/', function(req, res){\n res.end('forum');\n });\n\n app.use('/blog', blog);\n app.use('/forum', forum);\n\n request(app)\n .get('/blog')\n ", "meta": {"filepath": "test/app.use.js", "language": "javascript", "file_size": 12605, "cut_index": 921, "middle_length": 229}}
{"prefix": "\n .post('/')\n .set('Content-Type', 'application/octet-stream')\n .send('the user is tobi')\n .expect(200, { buf: '746865207573657220697320746f6269' }, done)\n })\n\n it('should 400 when invalid content-length', function (done) {\n var app = express()\n\n app.use(function (req, res, next) {\n req.headers['content-length'] = '20' // bad length\n next()\n })\n\n app.use(express.raw())\n\n app.post('/', function (req, res) {\n if (Buffer.isBuffer(req.body)) {\n res.json", "suffix": "nt length/, done)\n })\n\n it('should handle Content-Length: 0', function (done) {\n request(this.app)\n .post('/')\n .set('Content-Type', 'application/octet-stream')\n .set('Content-Length', '0')\n .expect(200, { buf: '' }, done)\n })\n\n ", "middle": "({ buf: req.body.toString('hex') })\n } else {\n res.json(req.body)\n }\n })\n\n request(app)\n .post('/')\n .set('Content-Type', 'application/octet-stream')\n .send('stuff')\n .expect(400, /conte", "meta": {"filepath": "test/express.raw.js", "language": "javascript", "file_size": 16296, "cut_index": 921, "middle_length": 229}}
{"prefix": "use strict'\n\nvar assert = require('node:assert')\nvar express = require('../');\nvar request = require('supertest');\n\ndescribe('middleware', function(){\n describe('.next()', function(){\n it('should behave like connect', function(done){\n var app = express()\n , calls = [];\n\n app.use(function(req, res, next){\n calls.push('one');\n next();\n });\n\n app.use(function(req, res, next){\n calls.push('two');\n next();\n });\n\n app.use(function(req, res){\n ", "suffix": " });\n });\n\n request(app)\n .get('/')\n .set('Content-Type', 'application/json')\n .send('{\"foo\":\"bar\"}')\n .expect('Content-Type', 'application/json')\n .expect(function () { assert.deepEqual(calls, ['one', 'two']) })\n ", "middle": " var buf = '';\n res.setHeader('Content-Type', 'application/json');\n req.setEncoding('utf8');\n req.on('data', function(chunk){ buf += chunk });\n req.on('end', function(){\n res.end(buf);\n ", "meta": {"filepath": "test/middleware.basic.js", "language": "javascript", "file_size": 1051, "cut_index": 513, "middle_length": 229}}
{"prefix": "ar express = require('../');\nvar request = require('supertest');\n\ndescribe('exports', function(){\n it('should expose Router', function(){\n assert.strictEqual(typeof express.Router, 'function')\n })\n\n it('should expose json middleware', function () {\n assert.equal(typeof express.json, 'function')\n assert.equal(express.json.length, 1)\n })\n\n it('should expose raw middleware', function () {\n assert.equal(typeof express.raw, 'function')\n assert.equal(express.raw.length, 1)\n })\n\n it('should e", "suffix": ", 'function')\n assert.equal(express.text.length, 1)\n })\n\n it('should expose urlencoded middleware', function () {\n assert.equal(typeof express.urlencoded, 'function')\n assert.equal(express.urlencoded.length, 1)\n })\n\n it('should expose the appl", "middle": "xpose static middleware', function () {\n assert.equal(typeof express.static, 'function')\n assert.equal(express.static.length, 2)\n })\n\n it('should expose text middleware', function () {\n assert.equal(typeof express.text", "meta": {"filepath": "test/exports.js", "language": "javascript", "file_size": 2344, "cut_index": 563, "middle_length": 229}}
{"prefix": "/')\n .set('Content-Type', 'text/plain')\n .send('user is tobi')\n .expect(200, '\"user is tobi\"', done)\n })\n\n it('should 400 when invalid content-length', function (done) {\n var app = express()\n\n app.use(function (req, res, next) {\n req.headers['content-length'] = '20' // bad length\n next()\n })\n\n app.use(express.text())\n\n app.post('/', function (req, res) {\n res.json(req.body)\n })\n\n request(app)\n .post('/')\n .set('Content-Type', 'text/plain')\n ", "suffix": "et('Content-Length', '0')\n .expect(200, '\"\"', done)\n })\n\n it('should handle empty message-body', function (done) {\n request(createApp({ limit: '1kb' }))\n .post('/')\n .set('Content-Type', 'text/plain')\n .set('Transfer-Encoding', 'ch", "middle": " .send('user')\n .expect(400, /content length/, done)\n })\n\n it('should handle Content-Length: 0', function (done) {\n request(createApp({ limit: '1kb' }))\n .post('/')\n .set('Content-Type', 'text/plain')\n .s", "meta": {"filepath": "test/express.text.js", "language": "javascript", "file_size": 17277, "cut_index": 921, "middle_length": 229}}
{"prefix": " = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.acceptsCharsets(type)', function(){\n describe('when Accept-Charset is not present', function(){\n it('should return true', function(done){\n var app = express();\n\n app.use(function(req, res, next){\n res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no');\n });\n\n request(app)\n .get('/')\n .expect('yes', done);\n })\n })\n\n describe('when Accept-Charset i", "suffix": " request(app)\n .get('/')\n .set('Accept-Charset', 'foo, bar, utf-8')\n .expect('yes', done);\n })\n\n it('should return false otherwise', function(done){\n var app = express();\n\n app.use(function(req, res, next){\n ", "middle": "s present', function () {\n it('should return true', function (done) {\n var app = express();\n\n app.use(function(req, res, next){\n res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no');\n });\n\n ", "meta": {"filepath": "test/req.acceptsCharsets.js", "language": "javascript", "file_size": 1609, "cut_index": 537, "middle_length": 229}}
{"prefix": "\n\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.acceptsLanguages', function(){\n it('should return language if accepted', function (done) {\n var app = express();\n\n app.get('/', function (req, res) {\n res.send({\n 'en-us': req.acceptsLanguages('en-us'),\n en: req.acceptsLanguages('en')\n })\n })\n\n request(app)\n .get('/')\n .set('Accept-Language', 'en;q=.5, en-us')\n .expect(200, {", "suffix": "uages('es')\n })\n })\n\n request(app)\n .get('/')\n .set('Accept-Language', 'en;q=.5, en-us')\n .expect(200, { es: false }, done)\n })\n\n describe('when Accept-Language is not present', function(){\n it('should alway", "middle": " 'en-us': 'en-us', en: 'en' }, done)\n })\n\n it('should be false if language not accepted', function(done){\n var app = express();\n\n app.get('/', function (req, res) {\n res.send({\n es: req.acceptsLang", "meta": {"filepath": "test/req.acceptsLanguages.js", "language": "javascript", "file_size": 1425, "cut_index": 524, "middle_length": 229}}
{"prefix": " = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.fresh', function(){\n it('should return true when the resource is not modified', function(done){\n var app = express();\n var etag = '\"12345\"';\n\n app.use(function(req, res){\n res.set('ETag', etag);\n res.send(req.fresh);\n });\n\n request(app)\n .get('/')\n .set('If-None-Match', etag)\n .expect(304, done);\n })\n\n it('should return false when the resource is modi", "suffix": "\"')\n .expect(200, 'false', done);\n })\n\n it('should return false without response headers', function(done){\n var app = express();\n\n app.disable('x-powered-by')\n app.use(function(req, res){\n res.send(req.fresh);\n });\n\n ", "middle": "fied', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.set('ETag', '\"123\"');\n res.send(req.fresh);\n });\n\n request(app)\n .get('/')\n .set('If-None-Match', '\"12345", "meta": {"filepath": "test/req.fresh.js", "language": "javascript", "file_size": 1664, "cut_index": 537, "middle_length": 229}}
{"prefix": "n(){\n describe('.host', function(){\n it('should return the Host when present', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.host);\n });\n\n request(app)\n .post('/')\n .set('Host', 'example.com')\n .expect('example.com', done);\n })\n\n it('should strip port number', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.host);\n });\n\n request(app)\n .post('/')\n .set('", "suffix": " null;\n res.end(String(req.host));\n });\n\n request(app)\n .post('/')\n .expect('undefined', done);\n })\n\n it('should work with IPv6 Host', function(done){\n var app = express();\n\n app.use(function(req, res){\n re", "middle": "Host', 'example.com:3000')\n .expect(200, 'example.com:3000', done);\n })\n\n it('should return undefined otherwise', function(done){\n var app = express();\n\n app.use(function(req, res){\n req.headers.host =", "meta": {"filepath": "test/req.host.js", "language": "javascript", "file_size": 3536, "cut_index": 614, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('req', function(){\n describe('.ip', function(){\n describe('when X-Forwarded-For is present', function(){\n describe('when \"trust proxy\" is enabled', function(){\n it('should return the client addr', function(done){\n var app = express();\n\n app.enable('trust proxy');\n\n app.use(function(req, res, next){\n res.send(req.ip);\n });\n\n request(app)\n .get('/')\n .set('X-Forwarded-For', 'client, ", "suffix": ".use(function(req, res, next){\n res.send(req.ip);\n });\n\n request(app)\n .get('/')\n .set('X-Forwarded-For', 'client, p1, p2')\n .expect('p1', done);\n })\n\n it('should return the addr after t", "middle": "p1, p2')\n .expect('client', done);\n })\n\n it('should return the addr after trusted proxy based on count', function (done) {\n var app = express();\n\n app.set('trust proxy', 2);\n\n app", "meta": {"filepath": "test/req.ip.js", "language": "javascript", "file_size": 2979, "cut_index": 563, "middle_length": 229}}
{"prefix": "ction () {\n describe('when given a mime type', function () {\n it('should return the type when matching', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.json(req.is('application/json'))\n })\n\n request(app)\n .post('/')\n .type('application/json')\n .send('{}')\n .expect(200, '\"application/json\"', done)\n })\n\n it('should return false when not matching', function (done) {\n var app = express()\n\n app.use(function (req, res)", "suffix": "\n var app = express()\n\n app.use(function (req, res) {\n res.json(req.is('application/json'))\n })\n\n request(app)\n .post('/')\n .type('application/json; charset=UTF-8')\n .send('{}')\n .expect(200, '\"application/jso", "middle": " {\n res.json(req.is('image/jpeg'))\n })\n\n request(app)\n .post('/')\n .type('application/json')\n .send('{}')\n .expect(200, 'false', done)\n })\n\n it('should ignore charset', function (done) {", "meta": {"filepath": "test/req.is.js", "language": "javascript", "file_size": 3782, "cut_index": 614, "middle_length": 229}}
{"prefix": "rtest');\n\ndescribe('req', function(){\n describe('.acceptsEncodings', function () {\n it('should return encoding if accepted', function (done) {\n var app = express();\n\n app.get('/', function (req, res) {\n res.send({\n gzip: req.acceptsEncodings('gzip'),\n deflate: req.acceptsEncodings('deflate')\n })\n })\n\n request(app)\n .get('/')\n .set('Accept-Encoding', ' gzip, deflate')\n .expect(200, { gzip: 'gzip', deflate: 'deflate' }, done)\n })\n", "suffix": "function(done){\n var app = express();\n\n app.get('/', function (req, res) {\n res.send({\n bogus: req.acceptsEncodings('bogus')\n })\n })\n\n request(app)\n .get('/')\n .set('Accept-Encoding', ' gzip, deflate", "middle": "\n it('should be false if encoding not accepted', ", "meta": {"filepath": "test/req.acceptsEncodings.js", "language": "javascript", "file_size": 953, "cut_index": 582, "middle_length": 52}}
{"prefix": "\n\nvar express = require('../')\n , request = require('supertest')\n , assert = require('node:assert');\n\ndescribe('req', function(){\n describe('.get(field)', function(){\n it('should return the header field value', function(done){\n var app = express();\n\n app.use(function(req, res){\n assert(req.get('Something-Else') === undefined);\n res.end(req.get('Content-Type'));\n });\n\n request(app)\n .post('/')\n .set('Content-Type', 'application/json')\n .expect('applicati", "suffix": " .set('Referrer', 'http://foobar.com')\n .expect('http://foobar.com', done);\n })\n\n it('should throw missing header name', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.end(req.get())\n })\n\n ", "middle": "on/json', done);\n })\n\n it('should special-case Referer', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.get('Referer'));\n });\n\n request(app)\n .post('/')\n ", "meta": {"filepath": "test/req.get.js", "language": "javascript", "file_size": 1415, "cut_index": 524, "middle_length": 229}}
{"prefix": " = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.ips', function(){\n describe('when X-Forwarded-For is present', function(){\n describe('when \"trust proxy\" is enabled', function(){\n it('should return an array of the specified addresses', function(done){\n var app = express();\n\n app.enable('trust proxy');\n\n app.use(function(req, res, next){\n res.send(req.ips);\n });\n\n request(app)\n .get(", "suffix": "'trust proxy', 2);\n\n app.use(function(req, res, next){\n res.send(req.ips);\n });\n\n request(app)\n .get('/')\n .set('X-Forwarded-For', 'client, p1, p2')\n .expect('[\"p1\",\"p2\"]', done);\n })\n", "middle": "'/')\n .set('X-Forwarded-For', 'client, p1, p2')\n .expect('[\"client\",\"p1\",\"p2\"]', done);\n })\n\n it('should stop at first untrusted', function(done){\n var app = express();\n\n app.set(", "meta": {"filepath": "test/req.ips.js", "language": "javascript", "file_size": 1743, "cut_index": 537, "middle_length": 229}}
{"prefix": "st = require('supertest')\n\ndescribe('req', function(){\n describe('.baseUrl', function(){\n it('should be empty for top-level route', function(done){\n var app = express()\n\n app.get('/:a', function(req, res){\n res.end(req.baseUrl)\n })\n\n request(app)\n .get('/foo')\n .expect(200, '', done)\n })\n\n it('should contain lower path', function(done){\n var app = express()\n var sub = express.Router()\n\n sub.get('/:b', function(req, res){\n res.end(req.baseU", "suffix": "ss.Router()\n var sub2 = express.Router()\n var sub3 = express.Router()\n\n sub3.get('/:d', function(req, res){\n res.end(req.baseUrl)\n })\n sub2.use('/:c', sub3)\n sub1.use('/:b', sub2)\n app.use('/:a', sub1)\n\n reque", "middle": "rl)\n })\n app.use('/:a', sub)\n\n request(app)\n .get('/foo/bar')\n .expect(200, '/foo', done);\n })\n\n it('should contain full lower path', function(done){\n var app = express()\n var sub1 = expre", "meta": {"filepath": "test/req.baseUrl.js", "language": "javascript", "file_size": 2120, "cut_index": 563, "middle_length": 229}}
{"prefix": "n(){\n describe('.hostname', function(){\n it('should return the Host when present', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.hostname);\n });\n\n request(app)\n .post('/')\n .set('Host', 'example.com')\n .expect('example.com', done);\n })\n\n it('should strip port number', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.end(req.hostname);\n });\n\n request(app)\n .post('/')\n", "suffix": " = null;\n res.end(String(req.hostname));\n });\n\n request(app)\n .post('/')\n .expect('undefined', done);\n })\n\n it('should work with IPv6 Host', function(done){\n var app = express();\n\n app.use(function(req, res){\n ", "middle": " .set('Host', 'example.com:3000')\n .expect('example.com', done);\n })\n\n it('should return undefined otherwise', function(done){\n var app = express();\n\n app.use(function(req, res){\n req.headers.host", "meta": {"filepath": "test/req.hostname.js", "language": "javascript", "file_size": 4420, "cut_index": 614, "middle_length": 229}}
{"prefix": " = require('..');\nvar request = require('supertest');\n\ndescribe('res', function(){\n describe('.links(obj)', function(){\n it('should set Link header field', function (done) {\n var app = express();\n\n app.use(function (req, res) {\n res.links({\n next: 'http://api.example.com/users?page=2',\n last: 'http://api.example.com/users?page=5'\n });\n res.end();\n });\n\n request(app)\n .get('/')\n .expect('Link', '<http://api.example.com/users?page=2>; re", "suffix": "res) {\n res.links({\n next: 'http://api.example.com/users?page=2',\n last: 'http://api.example.com/users?page=5'\n });\n\n res.links({\n prev: 'http://api.example.com/users?page=1'\n });\n\n res.end();\n ", "middle": "l=\"next\", <http://api.example.com/users?page=5>; rel=\"last\"')\n .expect(200, done);\n })\n\n it('should set Link header field for multiple calls', function (done) {\n var app = express();\n\n app.use(function (req, ", "meta": {"filepath": "test/res.links.js", "language": "javascript", "file_size": 1877, "cut_index": 537, "middle_length": 229}}
{"prefix": "s = require('../lib/utils');\n\ndescribe('utils.etag(body, encoding)', function(){\n it('should support strings', function(){\n assert.strictEqual(utils.etag('express!'),\n '\"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg\"')\n })\n\n it('should support utf8 strings', function(){\n assert.strictEqual(utils.etag('express❤', 'utf8'),\n '\"a-JBiXf7GyzxwcrxY4hVXUwa7tmks\"')\n })\n\n it('should support buffer', function(){\n assert.strictEqual(utils.etag(Buffer.from('express!')),\n '\"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg\"')\n ", "suffix": "with a malformed parameter and break the loop in acceptParams', () => {\n const result = utils.normalizeType('text/plain;invalid');\n assert.deepEqual(result,{\n value: 'text/plain',\n quality: 1,\n params: {} // No parameters are added sin", "middle": " })\n\n it('should support empty string', function(){\n assert.strictEqual(utils.etag(''),\n '\"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk\"')\n })\n})\n\ndescribe('utils.normalizeType acceptParams method', () => {\n it('should handle a type ", "meta": {"filepath": "test/utils.js", "language": "javascript", "file_size": 3768, "cut_index": 614, "middle_length": 229}}
{"prefix": "rvice', function(){\n describe('GET /api/users', function(){\n describe('without an api key', function(){\n it('should respond with 400 bad request', function(done){\n request(app)\n .get('/api/users')\n .expect(400, done);\n })\n })\n\n describe('with an invalid api key', function(){\n it('should respond with 401 unauthorized', function(done){\n request(app)\n .get('/api/users?api-key=rawr')\n .expect(401, done);\n })\n })\n\n describe('with a val", "suffix": "{\"name\":\"tobi\"},{\"name\":\"loki\"},{\"name\":\"jane\"}]', done)\n })\n })\n })\n\n describe('GET /api/repos', function(){\n describe('without an api key', function(){\n it('should respond with 400 bad request', function(done){\n request(app)\n ", "middle": "id api key', function(){\n it('should respond users json', function(done){\n request(app)\n .get('/api/users?api-key=foo')\n .expect('Content-Type', 'application/json; charset=utf-8')\n .expect(200, '[", "meta": {"filepath": "test/acceptance/web-service.js", "language": "javascript", "file_size": 3129, "cut_index": 614, "middle_length": 229}}
{"prefix": "est = require('supertest')\n\ndescribe('req', function(){\n describe('.range(size)', function(){\n it('should return parsed ranges', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.json(req.range(120))\n })\n\n request(app)\n .get('/')\n .set('Range', 'bytes=0-50,51-100')\n .expect(200, '[{\"start\":0,\"end\":50},{\"start\":51,\"end\":100}]', done)\n })\n\n it('should cap to the given size', function (done) {\n var app = express()\n\n app.use", "suffix": "e when open-ended', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.json(req.range(75))\n })\n\n request(app)\n .get('/')\n .set('Range', 'bytes=0-')\n .expect(200, '[{\"start\":0,\"end\":74}]', d", "middle": "(function (req, res) {\n res.json(req.range(75))\n })\n\n request(app)\n .get('/')\n .set('Range', 'bytes=0-100')\n .expect(200, '[{\"start\":0,\"end\":74}]', done)\n })\n\n it('should cap to the given siz", "meta": {"filepath": "test/req.range.js", "language": "javascript", "file_size": 2351, "cut_index": 563, "middle_length": 229}}
{"prefix": " express = require('../')\n , request = require('supertest')\n , cookieParser = require('cookie-parser')\n\ndescribe('req', function(){\n describe('.signedCookies', function(){\n it('should return a signed JSON cookie', function(done){\n var app = express();\n\n app.use(cookieParser('secret'));\n\n app.use(function(req, res){\n if (req.path === '/set') {\n res.cookie('obj', { foo: 'bar' }, { signed: true });\n res.end();\n } else {\n res.send(req.signedCookies);", "suffix": "'/set')\n .end(function(err, res){\n if (err) return done(err);\n var cookie = res.header['set-cookie'];\n\n request(app)\n .get('/')\n .set('Cookie', cookie)\n .expect(200, { obj: { foo: 'bar' } }, done)\n });\n ", "middle": "\n }\n });\n\n request(app)\n .get(", "meta": {"filepath": "test/req.signedCookies.js", "language": "javascript", "file_size": 851, "cut_index": 529, "middle_length": 52}}
{"prefix": "ar express = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.query', function(){\n it('should default to {}', function(done){\n var app = createApp();\n\n request(app)\n .get('/')\n .expect(200, '{}', done);\n });\n\n it('should default to parse simple keys', function (done) {\n var app = createApp();\n\n request(app)\n .get('/?user[name]=tj')\n .expect(200, '{\"user[name]\":\"tj\"}', done);\n });\n\n describe('when \"query parser", "suffix": "200, '{\"foo\":[{\"bar\":\"baz\",\"fizz\":\"buzz\"},\"done!\"]}', done);\n });\n\n it('should parse parameters with dots', function (done) {\n var app = createApp('extended');\n\n request(app)\n .get('/?user.name=tj')\n .expect(200, '{\"us", "middle": "\" is extended', function () {\n it('should parse complex keys', function (done) {\n var app = createApp('extended');\n\n request(app)\n .get('/?foo[0][bar]=baz&foo[0][fizz]=buzz&foo[]=done!')\n .expect(", "meta": {"filepath": "test/req.query.js", "language": "javascript", "file_size": 2703, "cut_index": 563, "middle_length": 229}}
{"prefix": "e strict'\n\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.stale', function(){\n it('should return false when the resource is not modified', function(done){\n var app = express();\n var etag = '\"12345\"';\n\n app.use(function(req, res){\n res.set('ETag', etag);\n res.send(req.stale);\n });\n\n request(app)\n .get('/')\n .set('If-None-Match', etag)\n .expect(304, done);\n })\n\n it('should return true whe", "suffix": "f-None-Match', '\"12345\"')\n .expect(200, 'true', done);\n })\n\n it('should return true without response headers', function(done){\n var app = express();\n\n app.disable('x-powered-by')\n app.use(function(req, res){\n res.send(req.s", "middle": "n the resource is modified', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.set('ETag', '\"123\"');\n res.send(req.stale);\n });\n\n request(app)\n .get('/')\n .set('I", "meta": {"filepath": "test/req.stale.js", "language": "javascript", "file_size": 1102, "cut_index": 515, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('req', function(){\n describe('.secure', function(){\n describe('when X-Forwarded-Proto is missing', function(){\n it('should return false when http', function(done){\n var app = express();\n\n app.get('/', function(req, res){\n res.send(req.secure ? 'yes' : 'no');\n });\n\n request(app)\n .get('/')\n .expect('no', done)\n })\n })\n })\n\n describe('.secure', function(){\n describe('when X-Forwarded-Proto is present", "suffix": " .get('/')\n .set('X-Forwarded-Proto', 'https')\n .expect('no', done)\n })\n\n it('should return true when \"trust proxy\" is enabled', function(done){\n var app = express();\n\n app.enable('trust proxy');\n\n app.get('/", "middle": "', function(){\n it('should return false when http', function(done){\n var app = express();\n\n app.get('/', function(req, res){\n res.send(req.secure ? 'yes' : 'no');\n });\n\n request(app)\n ", "meta": {"filepath": "test/req.secure.js", "language": "javascript", "file_size": 2457, "cut_index": 563, "middle_length": 229}}
{"prefix": "use strict'\n\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('req', function(){\n describe('.xhr', function(){\n before(function () {\n this.app = express()\n this.app.get('/', function (req, res) {\n res.send(req.xhr)\n })\n })\n\n it('should return true when X-Requested-With is xmlhttprequest', function(done){\n request(this.app)\n .get('/')\n .set('X-Requested-With', 'xmlhttprequest')\n .expect(200, 'true', done)\n })\n\n it('shou", "suffix": "\n request(this.app)\n .get('/')\n .set('X-Requested-With', 'blahblah')\n .expect(200, 'false', done)\n })\n\n it('should return false when not present', function(done){\n request(this.app)\n .get('/')\n .expect(200", "middle": "ld case-insensitive', function(done){\n request(this.app)\n .get('/')\n .set('X-Requested-With', 'XMLHttpRequest')\n .expect(200, 'true', done)\n })\n\n it('should return false otherwise', function(done){", "meta": {"filepath": "test/req.xhr.js", "language": "javascript", "file_size": 1030, "cut_index": 513, "middle_length": 229}}
{"prefix": "fer } = require('node:buffer');\n\nvar express = require('../')\n , request = require('supertest');\n\ndescribe('res', function(){\n describe('.attachment()', function(){\n it('should Content-Disposition to attachment', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.attachment().send('foo');\n });\n\n request(app)\n .get('/')\n .expect('Content-Disposition', 'attachment', done);\n })\n })\n\n describe('.attachment(filename)', function(){\n it('shoul", "suffix": "expect('Content-Disposition', 'attachment; filename=\"image.png\"', done);\n })\n\n it('should set the Content-Type', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.attachment('/path/to/image.png');\n res.s", "middle": "d add the filename param', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.attachment('/path/to/image.png');\n res.send('foo');\n });\n\n request(app)\n .get('/')\n .", "meta": {"filepath": "test/res.attachment.js", "language": "javascript", "file_size": 1948, "cut_index": 537, "middle_length": 229}}
{"prefix": "t('should generate a JSON cookie', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.cookie('user', { name: 'tobi' }).end();\n });\n\n request(app)\n .get('/')\n .expect('Set-Cookie', 'user=j%3A%7B%22name%22%3A%22tobi%22%7D; Path=/')\n .expect(200, done)\n })\n })\n\n describe('.cookie(name, string)', function(){\n it('should set a cookie', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.cookie('name', 't", "suffix": "app.use(function(req, res){\n res.cookie('name', 'tobi');\n res.cookie('age', 1);\n res.cookie('gender', '?');\n res.end();\n });\n\n request(app)\n .get('/')\n .expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path", "middle": "obi').end();\n });\n\n request(app)\n .get('/')\n .expect('Set-Cookie', 'name=tobi; Path=/')\n .expect(200, done)\n })\n\n it('should allow multiple calls', function(done){\n var app = express();\n\n ", "meta": {"filepath": "test/res.cookie.js", "language": "javascript", "file_size": 7428, "cut_index": 716, "middle_length": 229}}
{"prefix": " res.format({\n 'text/plain': function(){\n res.send('hey');\n },\n\n 'text/html': function(){\n res.send('<p>hey</p>');\n },\n\n 'application/json': function(a, b, c){\n assert(req === a)\n assert(res === b)\n assert(next === c)\n res.send({ message: 'hey' });\n }\n });\n});\n\napp1.use(function(err, req, res, next){\n if (!err.types) throw err;\n res.status(err.status)\n res.send('Supports: ' + err.types.join(', '))\n})\n\nvar app2 = express();\n\napp2.use(function(req, res, next", "suffix": "tatus)\n res.send('Supports: ' + err.types.join(', '))\n})\n\nvar app3 = express();\n\napp3.use(function(req, res, next){\n res.format({\n text: function(){ res.send('hey') },\n default: function (a, b, c) {\n assert(req === a)\n assert(res === b)\n ", "middle": "){\n res.format({\n text: function(){ res.send('hey') },\n html: function(){ res.send('<p>hey</p>') },\n json: function(){ res.send({ message: 'hey' }) }\n });\n});\n\napp2.use(function(err, req, res, next){\n res.status(err.s", "meta": {"filepath": "test/res.format.js", "language": "javascript", "file_size": 5901, "cut_index": 716, "middle_length": 229}}
{"prefix": "bject)', function(){\n it('should respond with jsonp', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.jsonp({ count: 1 });\n });\n\n request(app)\n .get('/?callback=something')\n .expect('Content-Type', 'text/javascript; charset=utf-8')\n .expect(200, /something\\(\\{\"count\":1\\}\\);/, done);\n })\n\n it('should use first callback parameter with jsonp', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.jso", "suffix": " })\n\n it('should ignore object callback parameter with jsonp', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.jsonp({ count: 1 });\n });\n\n request(app)\n .get('/?callback[a]=something')\n .exp", "middle": "np({ count: 1 });\n });\n\n request(app)\n .get('/?callback=something&callback=somethingelse')\n .expect('Content-Type', 'text/javascript; charset=utf-8')\n .expect(200, /something\\(\\{\"count\":1\\}\\);/, done);\n ", "meta": {"filepath": "test/res.jsonp.js", "language": "javascript", "file_size": 9154, "cut_index": 716, "middle_length": 229}}
{"prefix": "on(){\n describe('.subdomains', function(){\n describe('when present', function(){\n it('should return an array', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.send(req.subdomains);\n });\n\n request(app)\n .get('/')\n .set('Host', 'tobi.ferrets.example.com')\n .expect(200, ['ferrets', 'tobi'], done);\n })\n\n it('should work with IPv4 address', function(done){\n var app = express();\n\n app.use(function(r", "suffix": "){\n var app = express();\n\n app.use(function(req, res){\n res.send(req.subdomains);\n });\n\n request(app)\n .get('/')\n .set('Host', '[::1]')\n .expect(200, [], done);\n })\n })\n\n describe('otherw", "middle": "eq, res){\n res.send(req.subdomains);\n });\n\n request(app)\n .get('/')\n .set('Host', '127.0.0.1')\n .expect(200, [], done);\n })\n\n it('should work with IPv6 address', function(done", "meta": {"filepath": "test/req.subdomains.js", "language": "javascript", "file_size": 4328, "cut_index": 614, "middle_length": 229}}
{"prefix": " = require('../')\n , request = require('supertest');\n\ndescribe('res', function(){\n describe('.clearCookie(name)', function(){\n it('should set a cookie passed expiry', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.clearCookie('sid').end();\n });\n\n request(app)\n .get('/')\n .expect('Set-Cookie', 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT')\n .expect(200, done)\n })\n })\n\n describe('.clearCookie(name, options)', function(){\n ", "suffix": "t('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')\n .expect(200, done)\n })\n\n it('should ignore maxAge', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.clearCookie('sid', { path:", "middle": " it('should set the given params', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.clearCookie('sid', { path: '/admin' }).end();\n });\n\n request(app)\n .get('/')\n .expec", "meta": {"filepath": "test/res.clearCookie.js", "language": "javascript", "file_size": 1606, "cut_index": 537, "middle_length": 229}}
{"prefix": "de:assert');\n\ndescribe('res', function(){\n describe('.json(object)', function(){\n it('should not support jsonp callbacks', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.json({ foo: 'bar' });\n });\n\n request(app)\n .get('/?callback=foo')\n .expect('{\"foo\":\"bar\"}', done);\n })\n\n it('should not override previous Content-Types', function(done){\n var app = express();\n\n app.get('/', function(req, res){\n res.type('application/vn", "suffix": " })\n\n describe('when given primitives', function(){\n it('should respond with json for null', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.json(null);\n });\n\n request(app)\n .get(", "middle": "d.example+json');\n res.json({ hello: 'world' });\n });\n\n request(app)\n .get('/')\n .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')\n .expect(200, '{\"hello\":\"world\"}', done);\n ", "meta": {"filepath": "test/res.json.js", "language": "javascript", "file_size": 4812, "cut_index": 614, "middle_length": 229}}
{"prefix": "(){\n describe('.download(path)', function(){\n it('should transfer as an attachment', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.download('test/fixtures/user.html');\n });\n\n request(app)\n .get('/')\n .expect('Content-Type', 'text/html; charset=utf-8')\n .expect('Content-Disposition', 'attachment; filename=\"user.html\"')\n .expect(200, '<p>{{user.name}}</p>', done)\n })\n\n it('should accept range requests', function (done) {\n ", "suffix": "er.name}}</p>', done)\n })\n\n it('should respond with requested byte range', function (done) {\n var app = express()\n\n app.get('/', function (req, res) {\n res.download('test/fixtures/user.html')\n })\n\n request(app)\n .get", "middle": " var app = express()\n\n app.get('/', function (req, res) {\n res.download('test/fixtures/user.html')\n })\n\n request(app)\n .get('/')\n .expect('Accept-Ranges', 'bytes')\n .expect(200, '<p>{{us", "meta": {"filepath": "test/res.download.js", "language": "javascript", "file_size": 13140, "cut_index": 921, "middle_length": 229}}
{"prefix": "ar express = require('..')\nvar request = require('supertest')\n\ndescribe('res', function () {\n describe('.append(field, val)', function () {\n it('should append multiple headers', function (done) {\n var app = express()\n\n app.use(function (req, res, next) {\n res.append('Set-Cookie', 'foo=bar')\n next()\n })\n\n app.use(function (req, res) {\n res.append('Set-Cookie', 'fizz=buzz')\n res.end()\n })\n\n request(app)\n .get('/')\n .expect(200)\n ", "suffix": " res.append('Set-Cookie', ['foo=bar', 'fizz=buzz'])\n res.end()\n })\n\n request(app)\n .get('/')\n .expect(200)\n .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz']))\n .end(done)\n })\n\n i", "middle": " .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz']))\n .end(done)\n })\n\n it('should accept array of values', function (done) {\n var app = express()\n\n app.use(function (req, res, next) {\n ", "meta": {"filepath": "test/res.append.js", "language": "javascript", "file_size": 2925, "cut_index": 563, "middle_length": 229}}
{"prefix": "default to a 302 redirect', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.redirect('http://google.com');\n });\n\n request(app)\n .get('/')\n .expect('location', 'http://google.com')\n .expect(302, done)\n })\n\n it('should encode \"url\"', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.redirect('https://google.com?q=\\u2603 §10')\n })\n\n request(app)\n .get('/')\n .expect('Location',", "suffix": " res.redirect('https://google.com?q=%A710')\n })\n\n request(app)\n .get('/')\n .expect('Location', 'https://google.com?q=%A710')\n .expect(302, done)\n })\n })\n\n describe('.redirect(status, url)', function(){\n it('should set the r", "middle": " 'https://google.com?q=%E2%98%83%20%C2%A710')\n .expect(302, done)\n })\n\n it('should not touch already-encoded sequences in \"url\"', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n ", "meta": {"filepath": "test/res.redirect.js", "language": "javascript", "file_size": 6121, "cut_index": 716, "middle_length": 229}}
{"prefix": "ction(done){\n var app = express();\n\n app.use(function(req, res){\n res.send();\n });\n\n request(app)\n .get('/')\n .expect(200, '', done);\n })\n })\n\n describe('.send(null)', function(){\n it('should set body to \"\"', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.send(null);\n });\n\n request(app)\n .get('/')\n .expect('Content-Length', '0')\n .expect(200, '', done);\n })\n })\n\n describe('.send(undefined)',", "suffix": " })\n })\n\n describe('.send(Number)', function(){\n it('should send as application/json', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.send(1000);\n });\n\n request(app)\n .get('/')\n .expect(", "middle": " function(){\n it('should set body to \"\"', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.send(undefined);\n });\n\n request(app)\n .get('/')\n .expect(200, '', done);\n ", "meta": {"filepath": "test/res.send.js", "language": "javascript", "file_size": 13688, "cut_index": 921, "middle_length": 229}}
{"prefix": "test')\n\ndescribe('res', function () {\n describe('.sendStatus(statusCode)', function () {\n it('should send the status code and message as body', function (done) {\n var app = express();\n\n app.use(function(req, res){\n res.sendStatus(201);\n });\n\n request(app)\n .get('/')\n .expect(201, 'Created', done);\n })\n\n it('should work with unknown code', function (done) {\n var app = express();\n\n app.use(function(req, res){\n res.sendStatus(599);\n });\n\n ", "suffix": "99', done);\n })\n\n it('should raise error for invalid status code', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.sendStatus(undefined).end()\n })\n\n request(app)\n .get('/')\n .expect", "middle": " request(app)\n .get('/')\n .expect(599, '5", "meta": {"filepath": "test/res.sendStatus.js", "language": "javascript", "file_size": 951, "cut_index": 582, "middle_length": 52}}
{"prefix": "unction () {\n describe('.status(code)', function () {\n\n it('should set the status code when valid', function (done) {\n var app = express();\n\n app.use(function (req, res) {\n res.status(200).end();\n });\n\n request(app)\n .get('/')\n .expect(200, done);\n });\n\n describe('accept valid ranges', function() {\n // not testing w/ 100, because that has specific meaning and behavior in Node as Expect: 100-continue\n it('should set the response status code to 101'", "suffix": "et the response status code to 201', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.status(201).end()\n })\n\n request(app)\n .get('/')\n .expect(201, done)\n })\n\n it('", "middle": ", function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.status(101).end()\n })\n\n request(app)\n .get('/')\n .expect(101, done)\n })\n\n it('should s", "meta": {"filepath": "test/res.status.js", "language": "javascript", "file_size": 4807, "cut_index": 614, "middle_length": 229}}
{"prefix": " = require('..');\nvar request = require('supertest');\nvar utils = require('./support/utils');\n\ndescribe('res.vary()', function(){\n describe('with no arguments', function(){\n it('should throw error', function (done) {\n var app = express();\n\n app.use(function (req, res) {\n res.vary();\n res.end();\n });\n\n request(app)\n .get('/')\n .expect(500, /field.*required/, done)\n })\n })\n\n describe('with an empty array', function(){\n it('should not set Vary', function ", "suffix": "one);\n })\n })\n\n describe('with an array', function(){\n it('should set the values', function (done) {\n var app = express();\n\n app.use(function (req, res) {\n res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);\n res.end", "middle": "(done) {\n var app = express();\n\n app.use(function (req, res) {\n res.vary([]);\n res.end();\n });\n\n request(app)\n .get('/')\n .expect(utils.shouldNotHaveHeader('Vary'))\n .expect(200, d", "meta": {"filepath": "test/res.vary.js", "language": "javascript", "file_size": 1984, "cut_index": 537, "middle_length": 229}}
{"prefix": "unction(){\n it('should set the header', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.location('http://google.com/').end();\n });\n\n request(app)\n .get('/')\n .expect('Location', 'http://google.com/')\n .expect(200, done)\n })\n\n it('should preserve trailing slashes when not present', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.location('http://google.com').end();\n });\n\n request(ap", "suffix": "n('https://google.com?q=\\u2603 §10').end()\n })\n\n request(app)\n .get('/')\n .expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')\n .expect(200, done)\n })\n\n it('should encode data uri', function (done) {\n var app", "middle": "p)\n .get('/')\n .expect('Location', 'http://google.com')\n .expect(200, done)\n })\n\n it('should encode \"url\"', function (done) {\n var app = express()\n\n app.use(function (req, res) {\n res.locatio", "meta": {"filepath": "test/res.location.js", "language": "javascript", "file_size": 8421, "cut_index": 716, "middle_length": 229}}
{"prefix": "ror: path must be a string to res.sendFile/, done)\n })\n\n it('should error for non-absolute path', function (done) {\n var app = createApp('name.txt')\n\n request(app)\n .get('/')\n .expect(500, /TypeError: path must be absolute/, done)\n })\n\n it('should transfer a file', function (done) {\n var app = createApp(path.resolve(fixtures, 'name.txt'));\n\n request(app)\n .get('/')\n .expect(200, 'tobi', done);\n });\n\n it('should transfer a file with special charac", "suffix": " var app = createApp(path.resolve(fixtures, 'name.txt'));\n\n request(app)\n .get('/')\n .expect('ETag', /^(?:W\\/)?\"[^\"]+\"$/)\n .expect(200, 'tobi', done);\n });\n\n it('should 304 when ETag matches', function (done) {\n var app ", "middle": "ters in string', function (done) {\n var app = createApp(path.resolve(fixtures, '% of dogs.txt'));\n\n request(app)\n .get('/')\n .expect(200, '20%', done);\n });\n\n it('should include ETag', function (done) {\n", "meta": {"filepath": "test/res.sendFile.js", "language": "javascript", "file_size": 23888, "cut_index": 1331, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('res', function(){\n describe('.type(str)', function(){\n it('should set the Content-Type based on a filename', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.type('foo.js').end('var name = \"tj\";');\n });\n\n request(app)\n .get('/')\n .expect('Content-Type', 'text/javascript; charset=utf-8')\n .end(done)\n })\n\n it('should default to application/octet-stream', function(done){\n var app = express();", "suffix": "ontent-Type with type/subtype', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.type('application/vnd.amazon.ebook')\n .end('var name = \"tj\";');\n });\n\n request(app)\n .get('/')\n .expect('", "middle": "\n\n app.use(function(req, res){\n res.type('rawr').end('var name = \"tj\";');\n });\n\n request(app)\n .get('/')\n .expect('Content-Type', 'application/octet-stream', done);\n })\n\n it('should set the C", "meta": {"filepath": "test/res.type.js", "language": "javascript", "file_size": 2812, "cut_index": 563, "middle_length": 229}}
{"prefix": ", function(){\n it('should support absolute paths', function(done){\n var app = createApp();\n\n app.locals.user = { name: 'tobi' };\n\n app.use(function(req, res){\n res.render(path.join(__dirname, 'fixtures', 'user.tmpl'))\n });\n\n request(app)\n .get('/')\n .expect('<p>tobi</p>', done);\n })\n\n it('should support absolute paths with \"view engine\"', function(done){\n var app = createApp();\n\n app.locals.user = { name: 'tobi' };\n app.set('view engine', 'tm", "suffix": "gine\" set and file extension to a non-engine module', function (done) {\n var app = createApp()\n\n app.locals.user = { name: 'tobi' }\n\n app.use(function (req, res) {\n res.render(path.join(__dirname, 'fixtures', 'broken.send'))\n })\n", "middle": "pl');\n\n app.use(function(req, res){\n res.render(path.join(__dirname, 'fixtures', 'user'))\n });\n\n request(app)\n .get('/')\n .expect('<p>tobi</p>', done);\n })\n\n it('should error without \"view en", "meta": {"filepath": "test/res.render.js", "language": "javascript", "file_size": 9137, "cut_index": 716, "middle_length": 229}}
{"prefix": "est = require('supertest');\n\ndescribe('res', function(){\n describe('.set(field, value)', function(){\n it('should set the response header field', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.set('Content-Type', 'text/x-foo; charset=utf-8').end();\n });\n\n request(app)\n .get('/')\n .expect('Content-Type', 'text/x-foo; charset=utf-8')\n .end(done);\n })\n\n it('should coerce to a string', function (done) {\n var app = express();\n\n ", "suffix": " })\n })\n\n describe('.set(field, values)', function(){\n it('should set multiple response header fields', function(done){\n var app = express();\n\n app.use(function(req, res){\n res.set('Set-Cookie', [\"type=ninja\", \"language=javascript\"]);", "middle": " app.use(function (req, res) {\n res.set('X-Number', 123);\n res.end(typeof res.get('X-Number'));\n });\n\n request(app)\n .get('/')\n .expect('X-Number', '123')\n .expect(200, 'string', done);\n ", "meta": {"filepath": "test/res.set.js", "language": "javascript", "file_size": 2960, "cut_index": 563, "middle_length": 229}}
{"prefix": "\n return res.headers['set-cookie'][0].split(';')[0];\n}\n\ndescribe('auth', function(){\n describe('GET /',function(){\n it('should redirect to /login', function(done){\n request(app)\n .get('/')\n .expect('Location', '/login')\n .expect(302, done)\n })\n })\n\n describe('GET /login',function(){\n it('should render login form', function(done){\n request(app)\n .get('/login')\n .expect(200, /<form/, done)\n })\n\n it('should display login error for bad user', function (done)", "suffix": " request(app)\n .get('/login')\n .set('Cookie', getCookie(res))\n .expect(200, /Authentication failed/, done)\n })\n })\n\n it('should display login error for bad password', function (done) {\n request(app)\n .post('/", "middle": " {\n request(app)\n .post('/login')\n .type('urlencoded')\n .send('username=not-tj&password=foobar')\n .expect('Location', '/login')\n .expect(302, function(err, res){\n if (err) return done(err)\n ", "meta": {"filepath": "test/acceptance/auth.js", "language": "javascript", "file_size": 3064, "cut_index": 614, "middle_length": 229}}
{"prefix": "ibe('cookie-sessions', function () {\n describe('GET /', function () {\n it('should display no views', function (done) {\n request(app)\n .get('/')\n .expect(200, 'viewed 1 times\\n', done)\n })\n\n it('should set a session cookie', function (done) {\n request(app)\n .get('/')\n .expect('Set-Cookie', /session=/)\n .expect(200, done)\n })\n\n it('should display 1 view on revisit', function (done) {\n request(app)\n .get('/')\n .expect(200, 'viewed 1 times\\n', fu", "suffix": ")\n request(app)\n .get('/')\n .set('Cookie', getCookies(res))\n .expect(200, 'viewed 2 times\\n', done)\n })\n })\n })\n})\n\nfunction getCookies(res) {\n return res.headers['set-cookie'].map(function (val) {\n return val.split", "middle": "nction (err, res) {\n if (err) return done(err", "meta": {"filepath": "test/acceptance/cookie-sessions.js", "language": "javascript", "file_size": 942, "cut_index": 606, "middle_length": 52}}
{"prefix": "equire('../../examples/downloads')\n , request = require('supertest');\n\ndescribe('downloads', function(){\n describe('GET /', function(){\n it('should have a link to amazing.txt', function(done){\n request(app)\n .get('/')\n .expect(/href=\"\\/files\\/amazing.txt\"/, done)\n })\n })\n\n describe('GET /files/notes/groceries.txt', function () {\n it('should have a download header', function (done) {\n request(app)\n .get('/files/notes/groceries.txt')\n .expect('Content-Disposition", "suffix": "zing.txt')\n .expect('Content-Disposition', 'attachment; filename=\"amazing.txt\"')\n .expect(200, done)\n })\n })\n\n describe('GET /files/missing.txt', function(){\n it('should respond with 404', function(done){\n request(app)\n .get('/f", "middle": "', 'attachment; filename=\"groceries.txt\"')\n .expect(200, done)\n })\n })\n\n describe('GET /files/amazing.txt', function(){\n it('should have a download header', function(done){\n request(app)\n .get('/files/ama", "meta": {"filepath": "test/acceptance/downloads.js", "language": "javascript", "file_size": 1265, "cut_index": 524, "middle_length": 229}}
{"prefix": "p = require('../../examples/multi-router')\nvar request = require('supertest')\n\ndescribe('multi-router', function(){\n describe('GET /',function(){\n it('should respond with root handler', function(done){\n request(app)\n .get('/')\n .expect(200, 'Hello from root route.', done)\n })\n })\n\n describe('GET /api/v1/',function(){\n it('should respond with APIv1 root handler', function(done){\n request(app)\n .get('/api/v1/')\n .expect(200, 'Hello from APIv1 root route.', done)\n }", "suffix": "ribe('GET /api/v2/',function(){\n it('should respond with APIv2 root handler', function(done){\n request(app)\n .get('/api/v2/')\n .expect(200, 'Hello from APIv2 root route.', done)\n })\n })\n\n describe('GET /api/v2/users',function(){\n ", "middle": ")\n })\n\n describe('GET /api/v1/users',function(){\n it('should respond with users from APIv1', function(done){\n request(app)\n .get('/api/v1/users')\n .expect(200, 'List of APIv1 users.', done)\n })\n })\n\n desc", "meta": {"filepath": "test/acceptance/multi-router.js", "language": "javascript", "file_size": 1173, "cut_index": 518, "middle_length": 229}}
{"prefix": " app = require('../../examples/params')\nvar request = require('supertest')\n\ndescribe('params', function(){\n describe('GET /', function(){\n it('should respond with instructions', function(done){\n request(app)\n .get('/')\n .expect(/Visit/,done)\n })\n })\n\n describe('GET /user/0', function(){\n it('should respond with a user', function(done){\n request(app)\n .get('/user/0')\n .expect(/user tj/,done)\n })\n })\n\n describe('GET /user/9', function(){\n it('should fa", "suffix": "one){\n request(app)\n .get('/users/0-2')\n .expect(/users tj, tobi, loki/, done)\n })\n })\n\n describe('GET /users/foo-bar', function(){\n it('should fail integer parsing', function(done){\n request(app)\n .get('/users/foo-bar')\n ", "middle": "il to find user', function(done){\n request(app)\n .get('/user/9')\n .expect(404, /failed to find user/, done)\n })\n })\n\n describe('GET /users/0-2', function(){\n it('should respond with three users', function(d", "meta": {"filepath": "test/acceptance/params.js", "language": "javascript", "file_size": 1064, "cut_index": 515, "middle_length": 229}}
{"prefix": "var request = require('supertest')\n , app = require('../../examples/route-map');\n\ndescribe('route-map', function(){\n describe('GET /users', function(){\n it('should respond with users', function(done){\n request(app)\n .get('/users')\n .expect('user list', done);\n })\n })\n\n describe('DELETE /users', function(){\n it('should delete users', function(done){\n request(app)\n .del('/users')\n .expect('delete users', done);\n })\n })\n\n describe('GET /users/:id', function(){\n ", "suffix": " request(app)\n .get('/users/12/pets')\n .expect('user 12\\'s pets', done);\n })\n })\n\n describe('GET /users/:id/pets/:pid', function(){\n it('should get a users pet', function(done){\n request(app)\n .del('/users/12/pets/2')\n .e", "middle": " it('should get a user', function(done){\n request(app)\n .get('/users/12')\n .expect('user 12', done);\n })\n })\n\n describe('GET /users/:id/pets', function(){\n it('should get a users pets', function(done){\n ", "meta": {"filepath": "test/acceptance/route-map.js", "language": "javascript", "file_size": 1048, "cut_index": 513, "middle_length": 229}}
{"prefix": "p = require('../../examples/vhost')\nvar request = require('supertest')\n\ndescribe('vhost', function(){\n describe('example.com', function(){\n describe('GET /', function(){\n it('should say hello', function(done){\n request(app)\n .get('/')\n .set('Host', 'example.com')\n .expect(200, /hello/i, done)\n })\n })\n\n describe('GET /foo', function(){\n it('should say foo', function(done){\n request(app)\n .get('/foo')\n .set('Host', 'example.com')\n ", "suffix": " .set('Host', 'foo.example.com')\n .expect(302, /Redirecting to http:\\/\\/example.com:3000\\/foo/, done)\n })\n })\n })\n\n describe('bar.example.com', function(){\n describe('GET /', function(){\n it('should redirect to /bar', function", "middle": " .expect(200, 'requested foo', done)\n })\n })\n })\n\n describe('foo.example.com', function(){\n describe('GET /', function(){\n it('should redirect to /foo', function(done){\n request(app)\n .get('/')\n ", "meta": {"filepath": "test/acceptance/vhost.js", "language": "javascript", "file_size": 1190, "cut_index": 518, "middle_length": 229}}
{"prefix": " = require('supertest')\n , app = require('../../examples/content-negotiation');\n\ndescribe('content-negotiation', function(){\n describe('GET /', function(){\n it('should default to text/html', function(done){\n request(app)\n .get('/')\n .expect(200, '<ul><li>Tobi</li><li>Loki</li><li>Jane</li></ul>', done)\n })\n\n it('should accept to text/plain', function(done){\n request(app)\n .get('/')\n .set('Accept', 'text/plain')\n .expect(200, ' - Tobi\\n - Loki\\n - Jane\\n', done)\n", "suffix": " })\n\n describe('GET /users', function(){\n it('should default to text/html', function(done){\n request(app)\n .get('/users')\n .expect(200, '<ul><li>Tobi</li><li>Loki</li><li>Jane</li></ul>', done)\n })\n\n it('should accept to text/plai", "middle": " })\n\n it('should accept to application/json', function(done){\n request(app)\n .get('/')\n .set('Accept', 'application/json')\n .expect(200, '[{\"name\":\"Tobi\"},{\"name\":\"Loki\"},{\"name\":\"Jane\"}]', done)\n })\n", "meta": {"filepath": "test/acceptance/content-negotiation.js", "language": "javascript", "file_size": 1402, "cut_index": 524, "middle_length": 229}}
{"prefix": ", request = require('supertest');\n\ndescribe('error-pages', function(){\n describe('GET /', function(){\n it('should respond with page list', function(done){\n request(app)\n .get('/')\n .expect(/Pages Example/, done)\n })\n })\n\n describe('Accept: text/html',function(){\n describe('GET /403', function(){\n it('should respond with 403', function(done){\n request(app)\n .get('/403')\n .expect(403, done)\n })\n })\n\n describe('GET /404', function(){\n it('sho", "suffix": "(app)\n .get('/500')\n .expect(500, done)\n })\n })\n })\n\n describe('Accept: application/json',function(){\n describe('GET /403', function(){\n it('should respond with 403', function(done){\n request(app)\n .get('/403')", "middle": "uld respond with 404', function(done){\n request(app)\n .get('/404')\n .expect(404, done)\n })\n })\n\n describe('GET /500', function(){\n it('should respond with 500', function(done){\n request", "meta": {"filepath": "test/acceptance/error-pages.js", "language": "javascript", "file_size": 2315, "cut_index": 563, "middle_length": 229}}
{"prefix": "examples/resource')\nvar request = require('supertest')\n\ndescribe('resource', function(){\n describe('GET /', function(){\n it('should respond with instructions', function(done){\n request(app)\n .get('/')\n .expect(/^<h1>Examples:<\\/h1>/,done)\n })\n })\n\n describe('GET /users', function(){\n it('should respond with all users', function(done){\n request(app)\n .get('/users')\n .expect(/^\\[{\"name\":\"tj\"},{\"name\":\"ciaran\"},{\"name\":\"aaron\"},{\"name\":\"guillermo\"},{\"name\":\"sim", "suffix": " })\n\n describe('GET /users/9', function(){\n it('should respond with error', function(done){\n request(app)\n .get('/users/9')\n .expect('{\"error\":\"Cannot find user\"}', done)\n })\n })\n\n describe('GET /users/1..3', function(){\n it", "middle": "on\"},{\"name\":\"tobi\"}\\]/,done)\n })\n })\n\n describe('GET /users/1', function(){\n it('should respond with user 1', function(done){\n request(app)\n .get('/users/1')\n .expect(/^{\"name\":\"ciaran\"}/,done)\n })\n", "meta": {"filepath": "test/acceptance/resource.js", "language": "javascript", "file_size": 1844, "cut_index": 537, "middle_length": 229}}
{"prefix": "/examples/cookies')\n , request = require('supertest');\nvar utils = require('../support/utils');\n\ndescribe('cookies', function(){\n describe('GET /', function(){\n it('should have a form', function(done){\n request(app)\n .get('/')\n .expect(/<form/, done);\n })\n\n it('should respond with no cookies', function(done){\n request(app)\n .get('/')\n .expect(utils.shouldNotHaveHeader('Set-Cookie'))\n .expect(200, done)\n })\n\n it('should respond to cookie', function(done){\n ", "suffix": "headers['set-cookie'][0])\n .expect(200, /Remembered/, done)\n })\n })\n })\n\n describe('GET /forget', function(){\n it('should clear cookie', function(done){\n request(app)\n .post('/')\n .type('urlencoded')\n .send({ remembe", "middle": " request(app)\n .post('/')\n .type('urlencoded')\n .send({ remember: 1 })\n .expect(302, function(err, res){\n if (err) return done(err)\n request(app)\n .get('/')\n .set('Cookie', res.", "meta": {"filepath": "test/acceptance/cookies.js", "language": "javascript", "file_size": 1746, "cut_index": 537, "middle_length": 229}}
{"prefix": "')\nvar request = require('supertest')\n\ndescribe('route-separation', function () {\n describe('GET /', function () {\n it('should respond with index', function (done) {\n request(app)\n .get('/')\n .expect(200, /Route Separation Example/, done)\n })\n })\n\n describe('GET /users', function () {\n it('should list users', function (done) {\n request(app)\n .get('/users')\n .expect(/TJ/)\n .expect(/Tobi/)\n .expect(200, done)\n })\n })\n\n describe('GET /user/:id', function", "suffix": "('/user/10')\n .expect(404, done)\n })\n })\n\n describe('GET /user/:id/view', function () {\n it('should get a user', function (done) {\n request(app)\n .get('/user/0/view')\n .expect(200, /Viewing user TJ/, done)\n })\n\n it('should", "middle": " () {\n it('should get a user', function (done) {\n request(app)\n .get('/user/0')\n .expect(200, /Viewing user TJ/, done)\n })\n\n it('should 404 on missing user', function (done) {\n request(app)\n .get", "meta": {"filepath": "test/acceptance/route-separation.js", "language": "javascript", "file_size": 2541, "cut_index": 563, "middle_length": 229}}
{"prefix": "(){\n describe('GET /', function(){\n it('should redirect to /users', function(done){\n request(app)\n .get('/')\n .expect('Location', '/users')\n .expect(302, done)\n })\n })\n\n describe('GET /pet/0', function(){\n it('should get pet', function(done){\n request(app)\n .get('/pet/0')\n .expect(200, /Tobi/, done)\n })\n })\n\n describe('GET /pet/0/edit', function(){\n it('should get pet edit page', function(done){\n request(app)\n .get('/pet/0/edit')\n .expect", "suffix": "rm-urlencoded')\n .send({ pet: { name: 'Boots' } })\n .expect(302, function (err, res) {\n if (err) return done(err);\n request(app)\n .get('/pet/3/edit')\n .expect(200, /Boots/, done)\n })\n })\n })\n\n describe('GET /", "middle": "(/<form/)\n .expect(200, /Tobi/, done)\n })\n })\n\n describe('PUT /pet/2', function(){\n it('should update the pet', function(done){\n request(app)\n .put('/pet/3')\n .set('Content-Type', 'application/x-www-fo", "meta": {"filepath": "test/acceptance/mvc.js", "language": "javascript", "file_size": 3292, "cut_index": 614, "middle_length": 229}}
{"prefix": "ssert = require('node:assert');\nconst { Buffer } = require('node:buffer');\n\n/**\n * Module exports.\n * @public\n */\n\nexports.shouldHaveBody = shouldHaveBody\nexports.shouldHaveHeader = shouldHaveHeader\nexports.shouldNotHaveBody = shouldNotHaveBody\nexports.shouldNotHaveHeader = shouldNotHaveHeader;\nexports.shouldSkipQuery = shouldSkipQuery\n\n/**\n * Assert that a supertest response has a specific body.\n *\n * @param {Buffer} buf\n * @returns {function}\n */\n\nfunction shouldHaveBody (buf) {\n return function (res) {\n", "suffix": "test response does have a header.\n *\n * @param {string} header Header name to check\n * @returns {function}\n */\n\nfunction shouldHaveHeader (header) {\n return function (res) {\n assert.ok((header.toLowerCase() in res.headers), 'should have header ' + head", "middle": " var body = !Buffer.isBuffer(res.body)\n ? Buffer.from(res.text)\n : res.body\n assert.ok(body, 'response has body')\n assert.strictEqual(body.toString('hex'), buf.toString('hex'))\n }\n}\n\n/**\n * Assert that a super", "meta": {"filepath": "test/support/utils.js", "language": "javascript", "file_size": 2089, "cut_index": 563, "middle_length": 229}}
|