mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 10:52:47 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
243
node_modules/express/lib/response.js
generated
vendored
243
node_modules/express/lib/response.js
generated
vendored
@@ -5,9 +5,11 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @api private
|
||||
* @private
|
||||
*/
|
||||
|
||||
var contentDisposition = require('content-disposition');
|
||||
@@ -38,15 +40,22 @@ var res = module.exports = {
|
||||
__proto__: http.ServerResponse.prototype
|
||||
};
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var charsetRegExp = /;\s*charset\s*=/;
|
||||
|
||||
/**
|
||||
* Set status `code`.
|
||||
*
|
||||
* @param {Number} code
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.status = function(code){
|
||||
res.status = function status(code) {
|
||||
this.statusCode = code;
|
||||
return this;
|
||||
};
|
||||
@@ -63,7 +72,7 @@ res.status = function(code){
|
||||
*
|
||||
* @param {Object} links
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.links = function(links){
|
||||
@@ -84,7 +93,7 @@ res.links = function(links){
|
||||
* res.send('<p>some html</p>');
|
||||
*
|
||||
* @param {string|number|boolean|object|Buffer} body
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.send = function send(body) {
|
||||
@@ -119,7 +128,7 @@ res.send = function send(body) {
|
||||
|
||||
deprecate('res.send(status): Use res.sendStatus(status) instead');
|
||||
this.statusCode = chunk;
|
||||
chunk = http.STATUS_CODES[chunk];
|
||||
chunk = statusCodes[chunk];
|
||||
}
|
||||
|
||||
switch (typeof chunk) {
|
||||
@@ -207,7 +216,7 @@ res.send = function send(body) {
|
||||
* res.json({ user: 'tj' });
|
||||
*
|
||||
* @param {string|number|boolean|object} obj
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.json = function json(obj) {
|
||||
@@ -249,7 +258,7 @@ res.json = function json(obj) {
|
||||
* res.jsonp({ user: 'tj' });
|
||||
*
|
||||
* @param {string|number|boolean|object} obj
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.jsonp = function jsonp(obj) {
|
||||
@@ -320,11 +329,11 @@ res.jsonp = function jsonp(obj) {
|
||||
* res.sendStatus(200);
|
||||
*
|
||||
* @param {number} statusCode
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.sendStatus = function sendStatus(statusCode) {
|
||||
var body = http.STATUS_CODES[statusCode] || String(statusCode);
|
||||
var body = statusCodes[statusCode] || String(statusCode);
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.type('txt');
|
||||
@@ -336,7 +345,7 @@ res.sendStatus = function sendStatus(statusCode) {
|
||||
* Transfer the file at the given `path`.
|
||||
*
|
||||
* Automatically sets the _Content-Type_ response header field.
|
||||
* The callback `fn(err)` is invoked when the transfer is complete
|
||||
* The callback `callback(err)` is invoked when the transfer is complete
|
||||
* or when an error occurs. Be sure to check `res.sentHeader`
|
||||
* if you wish to attempt responding, as the header and some data
|
||||
* may have already been transferred.
|
||||
@@ -370,13 +379,15 @@ res.sendStatus = function sendStatus(statusCode) {
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.sendFile = function sendFile(path, options, fn) {
|
||||
res.sendFile = function sendFile(path, options, callback) {
|
||||
var done = callback;
|
||||
var req = this.req;
|
||||
var res = this;
|
||||
var next = req.next;
|
||||
var opts = options || {};
|
||||
|
||||
if (!path) {
|
||||
throw new TypeError('path argument is required to res.sendFile');
|
||||
@@ -384,23 +395,21 @@ res.sendFile = function sendFile(path, options, fn) {
|
||||
|
||||
// support function as second arg
|
||||
if (typeof options === 'function') {
|
||||
fn = options;
|
||||
options = {};
|
||||
done = options;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (!options.root && !isAbsolute(path)) {
|
||||
if (!opts.root && !isAbsolute(path)) {
|
||||
throw new TypeError('path must be absolute or specify root to res.sendFile');
|
||||
}
|
||||
|
||||
// create file stream
|
||||
var pathname = encodeURI(path);
|
||||
var file = send(req, pathname, options);
|
||||
var file = send(req, pathname, opts);
|
||||
|
||||
// transfer
|
||||
sendfile(res, file, options, function (err) {
|
||||
if (fn) return fn(err);
|
||||
sendfile(res, file, opts, function (err) {
|
||||
if (done) return done(err);
|
||||
if (err && err.code === 'EISDIR') return next();
|
||||
|
||||
// next() all but write errors
|
||||
@@ -414,7 +423,7 @@ res.sendFile = function sendFile(path, options, fn) {
|
||||
* Transfer the file at the given `path`.
|
||||
*
|
||||
* Automatically sets the _Content-Type_ response header field.
|
||||
* The callback `fn(err)` is invoked when the transfer is complete
|
||||
* The callback `callback(err)` is invoked when the transfer is complete
|
||||
* or when an error occurs. Be sure to check `res.sentHeader`
|
||||
* if you wish to attempt responding, as the header and some data
|
||||
* may have already been transferred.
|
||||
@@ -448,28 +457,28 @@ res.sendFile = function sendFile(path, options, fn) {
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.sendfile = function(path, options, fn){
|
||||
res.sendfile = function (path, options, callback) {
|
||||
var done = callback;
|
||||
var req = this.req;
|
||||
var res = this;
|
||||
var next = req.next;
|
||||
var opts = options || {};
|
||||
|
||||
// support function as second arg
|
||||
if (typeof options === 'function') {
|
||||
fn = options;
|
||||
options = {};
|
||||
done = options;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
// create file stream
|
||||
var file = send(req, path, options);
|
||||
var file = send(req, path, opts);
|
||||
|
||||
// transfer
|
||||
sendfile(res, file, options, function (err) {
|
||||
if (fn) return fn(err);
|
||||
sendfile(res, file, opts, function (err) {
|
||||
if (done) return done(err);
|
||||
if (err && err.code === 'EISDIR') return next();
|
||||
|
||||
// next() all but write errors
|
||||
@@ -486,33 +495,34 @@ res.sendfile = deprecate.function(res.sendfile,
|
||||
* Transfer the file at the given `path` as an attachment.
|
||||
*
|
||||
* Optionally providing an alternate attachment `filename`,
|
||||
* and optional callback `fn(err)`. The callback is invoked
|
||||
* and optional callback `callback(err)`. The callback is invoked
|
||||
* when the data transfer is complete, or when an error has
|
||||
* ocurred. Be sure to check `res.headersSent` if you plan to respond.
|
||||
*
|
||||
* This method uses `res.sendfile()`.
|
||||
*
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.download = function download(path, filename, fn) {
|
||||
res.download = function download(path, filename, callback) {
|
||||
var done = callback;
|
||||
var name = filename;
|
||||
|
||||
// support function as second arg
|
||||
if (typeof filename === 'function') {
|
||||
fn = filename;
|
||||
filename = null;
|
||||
done = filename;
|
||||
name = null;
|
||||
}
|
||||
|
||||
filename = filename || path;
|
||||
|
||||
// set Content-Disposition when file is sent
|
||||
var headers = {
|
||||
'Content-Disposition': contentDisposition(filename)
|
||||
'Content-Disposition': contentDisposition(name || path)
|
||||
};
|
||||
|
||||
// Resolve the full path for sendFile
|
||||
var fullPath = resolve(path);
|
||||
|
||||
return this.sendFile(fullPath, { headers: headers }, fn);
|
||||
return this.sendFile(fullPath, { headers: headers }, done);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -529,14 +539,16 @@ res.download = function download(path, filename, fn) {
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.contentType =
|
||||
res.type = function(type){
|
||||
return this.set('Content-Type', ~type.indexOf('/')
|
||||
? type
|
||||
: mime.lookup(type));
|
||||
res.type = function contentType(type) {
|
||||
var ct = type.indexOf('/') === -1
|
||||
? mime.lookup(type)
|
||||
: type;
|
||||
|
||||
return this.set('Content-Type', ct);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -593,7 +605,7 @@ res.type = function(type){
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.format = function(obj){
|
||||
@@ -604,7 +616,9 @@ res.format = function(obj){
|
||||
if (fn) delete obj.default;
|
||||
var keys = Object.keys(obj);
|
||||
|
||||
var key = req.accepts(keys);
|
||||
var key = keys.length > 0
|
||||
? req.accepts(keys)
|
||||
: false;
|
||||
|
||||
this.vary("Accept");
|
||||
|
||||
@@ -615,7 +629,7 @@ res.format = function(obj){
|
||||
fn();
|
||||
} else {
|
||||
var err = new Error('Not Acceptable');
|
||||
err.status = 406;
|
||||
err.status = err.statusCode = 406;
|
||||
err.types = normalizeTypes(keys).map(function(o){ return o.value });
|
||||
next(err);
|
||||
}
|
||||
@@ -628,7 +642,7 @@ res.format = function(obj){
|
||||
*
|
||||
* @param {String} filename
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.attachment = function attachment(filename) {
|
||||
@@ -653,7 +667,7 @@ res.attachment = function attachment(filename) {
|
||||
* @param {String} field
|
||||
* @param {String|Array} val
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.append = function append(field, val) {
|
||||
@@ -682,22 +696,26 @@ res.append = function append(field, val) {
|
||||
*
|
||||
* Aliased as `res.header()`.
|
||||
*
|
||||
* @param {String|Object|Array} field
|
||||
* @param {String} val
|
||||
* @param {String|Object} field
|
||||
* @param {String|Array} val
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.set =
|
||||
res.header = function header(field, val) {
|
||||
if (arguments.length === 2) {
|
||||
if (Array.isArray(val)) val = val.map(String);
|
||||
else val = String(val);
|
||||
if ('content-type' == field.toLowerCase() && !/;\s*charset\s*=/.test(val)) {
|
||||
var charset = mime.charsets.lookup(val.split(';')[0]);
|
||||
if (charset) val += '; charset=' + charset.toLowerCase();
|
||||
var value = Array.isArray(val)
|
||||
? val.map(String)
|
||||
: String(val);
|
||||
|
||||
// add charset to content-type
|
||||
if (field.toLowerCase() === 'content-type' && !charsetRegExp.test(value)) {
|
||||
var charset = mime.charsets.lookup(value.split(';')[0]);
|
||||
if (charset) value += '; charset=' + charset.toLowerCase();
|
||||
}
|
||||
this.setHeader(field, val);
|
||||
|
||||
this.setHeader(field, value);
|
||||
} else {
|
||||
for (var key in field) {
|
||||
this.set(key, field[key]);
|
||||
@@ -711,7 +729,7 @@ res.header = function header(field, val) {
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.get = function(field){
|
||||
@@ -724,18 +742,17 @@ res.get = function(field){
|
||||
* @param {String} name
|
||||
* @param {Object} options
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.clearCookie = function(name, options){
|
||||
var opts = { expires: new Date(1), path: '/' };
|
||||
return this.cookie(name, '', options
|
||||
? merge(opts, options)
|
||||
: opts);
|
||||
res.clearCookie = function clearCookie(name, options) {
|
||||
var opts = merge({ expires: new Date(1), path: '/' }, options);
|
||||
|
||||
return this.cookie(name, '', opts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set cookie `name` to `val`, with the given `options`.
|
||||
* Set cookie `name` to `value`, with the given `options`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
@@ -752,41 +769,43 @@ res.clearCookie = function(name, options){
|
||||
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String|Object} val
|
||||
* @param {String|Object} value
|
||||
* @param {Options} options
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.cookie = function(name, val, options){
|
||||
options = merge({}, options);
|
||||
res.cookie = function (name, value, options) {
|
||||
var opts = merge({}, options);
|
||||
var secret = this.req.secret;
|
||||
var signed = options.signed;
|
||||
if (signed && !secret) throw new Error('cookieParser("secret") required for signed cookies');
|
||||
if ('number' == typeof val) val = val.toString();
|
||||
if ('object' == typeof val) val = 'j:' + JSON.stringify(val);
|
||||
if (signed) val = 's:' + sign(val, secret);
|
||||
if ('maxAge' in options) {
|
||||
options.expires = new Date(Date.now() + options.maxAge);
|
||||
options.maxAge /= 1000;
|
||||
}
|
||||
if (null == options.path) options.path = '/';
|
||||
var headerVal = cookie.serialize(name, String(val), options);
|
||||
var signed = opts.signed;
|
||||
|
||||
// supports multiple 'res.cookie' calls by getting previous value
|
||||
var prev = this.get('Set-Cookie');
|
||||
if (prev) {
|
||||
if (Array.isArray(prev)) {
|
||||
headerVal = prev.concat(headerVal);
|
||||
} else {
|
||||
headerVal = [prev, headerVal];
|
||||
}
|
||||
if (signed && !secret) {
|
||||
throw new Error('cookieParser("secret") required for signed cookies');
|
||||
}
|
||||
this.set('Set-Cookie', headerVal);
|
||||
|
||||
var val = typeof value === 'object'
|
||||
? 'j:' + JSON.stringify(value)
|
||||
: String(value);
|
||||
|
||||
if (signed) {
|
||||
val = 's:' + sign(val, secret);
|
||||
}
|
||||
|
||||
if ('maxAge' in opts) {
|
||||
opts.expires = new Date(Date.now() + opts.maxAge);
|
||||
opts.maxAge /= 1000;
|
||||
}
|
||||
|
||||
if (opts.path == null) {
|
||||
opts.path = '/';
|
||||
}
|
||||
|
||||
this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the location header to `url`.
|
||||
*
|
||||
@@ -801,17 +820,19 @@ res.cookie = function(name, val, options){
|
||||
*
|
||||
* @param {String} url
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.location = function(url){
|
||||
var req = this.req;
|
||||
res.location = function location(url) {
|
||||
var loc = url;
|
||||
|
||||
// "back" is an alias for the referrer
|
||||
if ('back' == url) url = req.get('Referrer') || '/';
|
||||
if (url === 'back') {
|
||||
loc = this.req.get('Referrer') || '/';
|
||||
}
|
||||
|
||||
// Respond
|
||||
this.set('Location', url);
|
||||
// set location
|
||||
this.set('Location', loc);
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -830,7 +851,7 @@ res.location = function(url){
|
||||
* res.redirect(301, 'http://example.com');
|
||||
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
||||
*
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.redirect = function redirect(url) {
|
||||
@@ -886,7 +907,7 @@ res.redirect = function redirect(url) {
|
||||
*
|
||||
* @param {Array|String} field
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.vary = function(field){
|
||||
@@ -911,31 +932,33 @@ res.vary = function(field){
|
||||
* - `cache` boolean hinting to the engine it should cache
|
||||
* - `filename` filename of the view being rendered
|
||||
*
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.render = function(view, options, fn){
|
||||
options = options || {};
|
||||
var self = this;
|
||||
res.render = function render(view, options, callback) {
|
||||
var app = this.req.app;
|
||||
var done = callback;
|
||||
var opts = options || {};
|
||||
var req = this.req;
|
||||
var app = req.app;
|
||||
var self = this;
|
||||
|
||||
// support callback function as second arg
|
||||
if ('function' == typeof options) {
|
||||
fn = options, options = {};
|
||||
if (typeof options === 'function') {
|
||||
done = options;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
// merge res.locals
|
||||
options._locals = self.locals;
|
||||
opts._locals = self.locals;
|
||||
|
||||
// default callback to respond
|
||||
fn = fn || function(err, str){
|
||||
done = done || function (err, str) {
|
||||
if (err) return req.next(err);
|
||||
self.send(str);
|
||||
};
|
||||
|
||||
// render
|
||||
app.render(view, options, fn);
|
||||
app.render(view, opts, done);
|
||||
};
|
||||
|
||||
// pipe the send file stream
|
||||
|
||||
Reference in New Issue
Block a user