How to use the express.response function in express

To help you get started, we’ve selected a few express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tisan-kit / tisan-web-ide / app.js View on Github external
if(str.indexOf('webkit')==-1){
    res.render('download_chrome');
  }else{
    next();
  }
})

app.use('/', routes);
app.use('/user', require('./routes/user'));
app.use('/workspace', require('./routes/workspace'));
app.use('/qiniu', require('./routes/qiniu'));
app.use('/object', require('./routes/object'));
app.use('/product', require('./routes/product'));

var response = express.response,
  _render = response.render;
response.render = function(view, options, callback) {
  options = options || {}; 
  if (options) {
    _.extend(options, {
      staticUrl:"http://7xnf9k.com1.z0.glb.clouddn.com/@/",
    }); 
  }   
  console.log(options);
  _render.call(this, view, options, callback)
}

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
github xiaozhongliu / node-api-seed / util / extender.js View on Github external
/* ******************************************************************
 * extends targets here
 ****************************************************************** */
const express = require('express')

Object.assign(express.response, {

    success(data, msg = 'success') {
        this.json({ code: 1, msg, data })
    },

    fail(code = -1, msg = 'fail') {
        this.json({ code, msg })
    },
})
github fosslife / delta / index.js View on Github external
const { port, uploadpath, users } = require('./config');
const logger = require('./core/logger');
const { resolve } = require('path');
const { NODE_ENV: env } = process.env;
const uploads = require('./routes/router');

/**
 * Middlewares and inits
 */
// Initialize index by 1000

app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(helmet());

express.response.sendFile = promisify(express.response.sendFile);

if (env === 'production') {
    const job = require('./core/cron');
    job.start();
    logger.info('Cronjob starting in production mode');
}
/**
 * Router
 */

/**
 * Note that favicon is kinda important here
 * as all the routes are analogues /, /favicon, /:url are
 * same for express, so if /favicon fails, it will try to
 * search for /favicon in URLs instead :(
 */
github LearnBoost / express-mongoose / index.js View on Github external
/**
 * Module dependencies.
 */

var express = require('express')
  , Promise = require('mongoose').Promise
  , Query = require('mongoose').Query
  , slice = require('sliced')

/**
 * Wrap response.render with support for mongoose
 * Queries and Promises.
 */

var render = express.response.render;
express.response.render = function expressmongoose_render (view, options, callback) {
  if (!options || 'function' == typeof options) {
    return render.call(this, view, options, callback);
  }

  var self = this;
  return resolve(options, function (err, result) {
    if (err) {
      return 'function' == typeof callback
        ? callback(err)
        : self.req.next(err);
    }

    // must return here so partials always work
    return render.call(self, view, result, callback);
  });
github chialab / math-api / bin / server.js View on Github external
// "multiValueQueryStringParameters": { List of query string parameters }
        pathParameters: Object.assign({}, this.params || {}),
        stageVariables: Object.assign({}, this.app.locals || {}),
        requestContext: {}, // TODO
        body: this.body,
        isBase64Encoded: false,
    };
};

/**
 * Build ExpressJS response from Lambda proxy output.
 *
 * @param {LambdaProxyOutput} res Lambda proxy response.
 * @returns {ThisType}
 */
express.response.constructor.prototype.fromLambdaResponse = function (res) {
    this.status(res.statusCode);
    if (res.headers) {
        this.set(res.headers);
    }
    if (res.body) {
        let buf = Buffer.from(res.body, res.isBase64Encoded ? 'base64' : 'utf8');
        this.set('Content-Length', buf.byteLength);
        this.write(buf);
    }
    this.end();

    return this;
};

const apigw = new express.Router();
github probr / probr-analysis / server / api / session / session.controller.spec.js View on Github external
/**
 * Created by seebi on 09.12.15.
 */

var dbURI    = 'mongodb://localhost/probr-core-test'
    , Chai = require('chai')
    , expect   = Chai.expect
    , mongoose = require('mongoose')
    , response = require('express').response
    , async = require('async')
    , Session = require('../session/session.model')
    , controller = require('./session.controller.js')
    ;

// Helper function to make the following tests shorter
// queries with the given parameters and runs expectFunction(results)
function getResponse(cb) {
    // Default parameters for when query not given
    query = {
        startTimestamp: new Date("2015-01-01 08:00:00").valueOf().toString(),
        endTimestamp:   new Date("2015-01-01 18:00:00").valueOf().toString()
    };

    // Construct request object
    var req = { query: query };
github Jashepp / express-http2-workaround / tests / express-http2-server.js View on Github external
it("has instance.responseHTTP2 not equal express.response (both same required file)",function(){
		expect(expressHTTP2WorkaroundMiddleware.instance.responseHTTP2).to.not.equal(express.response);
	});
github codemanki / cloudscraper / test / helper.js View on Github external
return this;
};

express.response.sendFixture = function (fileName) {
  return this.send(helper.getFixture(fileName));
};

express.response.sendChallenge = function (fileName) {
  return this.cloudflare().status(503).sendFixture(fileName);
};

express.response.sendCaptcha = function (fileName) {
  return this.cloudflare().status(403).sendFixture(fileName);
};

express.response.endAbruptly = function () {
  this.connection.write(
    'HTTP/1.1 500\r\n' +
    'Content-Type: text/plain\r\n' +
    'Transfer-Encoding: chunked\r\n\r\n'
  );
  this.end();
};

module.exports = helper;
github ngnjs / NGN / lib / web / Server.js View on Github external
onXXX: function(code){
		this.emit('xxx',{code:code,response:express.response});
		this.onSend();
	}
});
github nulltask / express-csv / lib / express-csv.js View on Github external
/*!
 * express-csv
 * Copyright 2011 Seiya Konno 
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var http = require('http')
  , express = require('express')
  , res = express.response || http.ServerResponse.prototype;

/**
 * Import package information.
 */

var package = require('../package');

/**
 * Library version.
 */

exports.version = package.version;

/**
 * CSV separator
 */