From 4267bafcc930c8d94094ad8d10f30ba729c6610f Mon Sep 17 00:00:00 2001 From: Walamana Date: Tue, 28 Nov 2017 20:56:56 +0100 Subject: [PATCH] ... Signed-off-by: Walamana --- app.js | 3 +- node_modules/errorhandler/HISTORY.md | 154 +++++++++++++++ node_modules/errorhandler/LICENSE | 23 +++ node_modules/errorhandler/README.md | 128 +++++++++++++ node_modules/errorhandler/index.js | 198 ++++++++++++++++++++ node_modules/errorhandler/package.json | 80 ++++++++ node_modules/errorhandler/public/error.html | 14 ++ node_modules/errorhandler/public/style.css | 35 ++++ package-lock.json | 9 + package.json | 1 + 10 files changed, 644 insertions(+), 1 deletion(-) create mode 100644 node_modules/errorhandler/HISTORY.md create mode 100644 node_modules/errorhandler/LICENSE create mode 100644 node_modules/errorhandler/README.md create mode 100644 node_modules/errorhandler/index.js create mode 100644 node_modules/errorhandler/package.json create mode 100644 node_modules/errorhandler/public/error.html create mode 100644 node_modules/errorhandler/public/style.css diff --git a/app.js b/app.js index 9b0cdd5..3b55857 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ var express = require("express"); var cookieParser = require("cookie-parser"); var path = require("path"); +var errorHandler = require("errorhandler"); var app = express(); app.use(cookieParser()); @@ -9,7 +10,7 @@ app.use((req, res, next) => { return next(); }); app.use(express.static(path.join(process.cwd(), "StaticPages"))); -app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); +app.use(errorHandler({ dumpExceptions: true, showStack: true })); var uuid = require("uuid/v4"); var mysql = require("mysql"); diff --git a/node_modules/errorhandler/HISTORY.md b/node_modules/errorhandler/HISTORY.md new file mode 100644 index 0000000..1ed3e28 --- /dev/null +++ b/node_modules/errorhandler/HISTORY.md @@ -0,0 +1,154 @@ +1.5.0 / 2016-11-15 +================== + + * Pretty print JSON error response + * deps: accepts@~1.3.3 + - deps: mime-types@~2.1.11 + - deps: negotiator@0.6.1 + * perf: front-load HTML template and stylesheet at middleware construction + * perf: only load template and stylesheet once + * perf: resolve file paths at start up + +1.4.3 / 2016-01-17 +================== + + * deps: accepts@~1.3.0 + - deps: mime-types@~2.1.7 + - deps: negotiator@0.6.0 + * deps: escape-html@~1.0.3 + - perf: enable strict mode + - perf: optimize string replacement + - perf: use faster string coercion + +1.4.2 / 2015-07-30 +================== + + * deps: accepts@~1.2.12 + - deps: mime-types@~2.1.4 + +1.4.1 / 2015-07-05 +================== + + * deps: accepts@~1.2.10 + - deps: mime-types@~2.1.2 + +1.4.0 / 2015-06-10 +================== + + * Add charset to the `Content-Type` header + * Support `statusCode` property on `Error` objects + * deps: accepts@~1.2.9 + - deps: mime-types@~2.1.1 + - deps: negotiator@0.5.3 + - perf: avoid argument reassignment & argument slice + - perf: avoid negotiator recursive construction + - perf: enable strict mode + - perf: remove unnecessary bitwise operator + * deps: escape-html@1.0.2 + +1.3.6 / 2015-05-14 +================== + + * deps: accepts@~1.2.7 + - deps: mime-types@~2.0.11 + - deps: negotiator@0.5.3 + +1.3.5 / 2015-03-14 +================== + + * deps: accepts@~1.2.5 + - deps: mime-types@~2.0.10 + +1.3.4 / 2015-02-15 +================== + + * deps: accepts@~1.2.4 + - deps: mime-types@~2.0.9 + - deps: negotiator@0.5.1 + +1.3.3 / 2015-01-31 +================== + + * deps: accepts@~1.2.3 + - deps: mime-types@~2.0.8 + +1.3.2 / 2015-01-01 +================== + + * Fix heading content to not include stack + +1.3.1 / 2014-12-31 +================== + + * deps: accepts@~1.2.2 + - deps: mime-types@~2.0.7 + - deps: negotiator@0.5.0 + +1.3.0 / 2014-11-22 +================== + + * Add `log` option + +1.2.4 / 2015-01-01 +================== + + * Fix heading content to not include stack + +1.2.3 / 2014-11-21 +================== + + * deps: accepts@~1.1.3 + - deps: mime-types@~2.0.3 + +1.2.2 / 2014-10-15 +================== + + * deps: accepts@~1.1.2 + - Fix error when media type has invalid parameter + - deps: negotiator@0.4.9 + +1.2.1 / 2014-10-12 +================== + + * deps: accepts@~1.1.1 + - deps: mime-types@~2.0.2 + - deps: negotiator@0.4.8 + +1.2.0 / 2014-09-02 +================== + + * Display error using `util.inspect` if no other representation + * deps: accepts@~1.1.0 + +1.1.1 / 2014-06-20 +================== + + * deps: accepts@~1.0.4 + - use `mime-types` + +1.1.0 / 2014-06-16 +================== + + * Display error on console formatted like `throw` + * Escape HTML with `escape-html` module + * Escape HTML in stack trace + * Escape HTML in title + * Fix up edge cases with error sent in response + * Set `X-Content-Type-Options: nosniff` header + * Use accepts for negotiation + +1.0.2 / 2014-06-05 +================== + + * Pass on errors from reading error files + +1.0.1 / 2014-04-29 +================== + + * Clean up error CSS + * Do not respond after headers sent + +1.0.0 / 2014-03-03 +================== + + * Genesis from `connect` diff --git a/node_modules/errorhandler/LICENSE b/node_modules/errorhandler/LICENSE new file mode 100644 index 0000000..386b7b6 --- /dev/null +++ b/node_modules/errorhandler/LICENSE @@ -0,0 +1,23 @@ +(The MIT License) + +Copyright (c) 2014 Jonathan Ong +Copyright (c) 2014-2015 Douglas Christopher Wilson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/errorhandler/README.md b/node_modules/errorhandler/README.md new file mode 100644 index 0000000..a945779 --- /dev/null +++ b/node_modules/errorhandler/README.md @@ -0,0 +1,128 @@ +# errorhandler + +[![NPM Version][npm-image]][npm-url] +[![NPM Downloads][downloads-image]][downloads-url] +[![Build Status][travis-image]][travis-url] +[![Test Coverage][coveralls-image]][coveralls-url] +[![Gratipay][gratipay-image]][gratipay-url] + +Development-only error handler middleware. + +This middleware is only intended to be used in a development environment, as +the _full error stack traces and internal details of any object passed to this +module_ will be sent back to the client when an error occurs. + +When an object is provided to Express as an error, this module will display +as much about this object as possible, and will do so by using content negotiation +for the response between HTML, JSON, and plain text. + + * When the object is a standard `Error` object, the string provided by the + `stack` property will be returned in HTML/text responses. + * When the object is a non-`Error` object, the result of + [util.inspect](https://nodejs.org/api/util.html#util_util_inspect_object_options) + will be returned in HTML/text responses. + * For JSON responses, the result will be an object with all enumerable properties + from the object in the response. + +## Install + +This is a [Node.js](https://nodejs.org/en/) module available through the +[npm registry](https://www.npmjs.com/). Installation is done using the +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): + +```sh +$ npm install errorhandler +``` + +## API + +```js +var errorhandler = require('errorhandler') +``` + +### errorhandler(options) + +Create new middleware to handle errors and respond with content negotiation. + +#### Options + +Error handler accepts these properties in the options object. + +##### log + +Provide a function to be called with the error and a string representation of +the error. Can be used to write the error to any desired location, or set to +`false` to only send the error back in the response. Called as +`log(err, str, req, res)` where `err` is the `Error` object, `str` is a string +representation of the error, `req` is the request object and `res` is the +response object (note, this function is invoked _after_ the response has been +written). + +The default value for this option is `true` unless `process.env.NODE_ENV === 'test'`. + +Possible values: + + * `true`: Log errors using `console.error(str)`. + * `false`: Only send the error back in the response. + * A function: pass the error to a function for handling. + +## Examples + +### Simple example + +Basic example of adding this middleware as the error handler only in development +with `connect` (`express` also can be used in this example). + +```js +var connect = require('connect') +var errorhandler = require('errorhandler') + +var app = connect() + +if (process.env.NODE_ENV === 'development') { + // only use in development + app.use(errorhandler()) +} +``` + +### Custom output location + +Sometimes you may want to output the errors to a different location than STDERR +during development, like a system notification, for example. + +```js +var connect = require('connect') +var errorhandler = require('errorhandler') +var notifier = require('node-notifier') + +var app = connect() + +if (process.env.NODE_ENV === 'development') { + // only use in development + app.use(errorhandler({log: errorNotification})) +} + +function errorNotification(err, str, req) { + var title = 'Error in ' + req.method + ' ' + req.url + + notifier.notify({ + title: title, + message: str + }) +} +``` + +## License + +[MIT](LICENSE) + +[npm-image]: https://img.shields.io/npm/v/errorhandler.svg +[npm-url]: https://npmjs.org/package/errorhandler +[travis-image]: https://img.shields.io/travis/expressjs/errorhandler/master.svg +[travis-url]: https://travis-ci.org/expressjs/errorhandler +[coveralls-image]: https://img.shields.io/coveralls/expressjs/errorhandler/master.svg +[coveralls-url]: https://coveralls.io/r/expressjs/errorhandler?branch=master +[downloads-image]: https://img.shields.io/npm/dm/errorhandler.svg +[downloads-url]: https://npmjs.org/package/errorhandler +[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg +[gratipay-url]: https://www.gratipay.com/dougwilson/ diff --git a/node_modules/errorhandler/index.js b/node_modules/errorhandler/index.js new file mode 100644 index 0000000..47eb22a --- /dev/null +++ b/node_modules/errorhandler/index.js @@ -0,0 +1,198 @@ +/*! + * errorhandler + * Copyright(c) 2010 Sencha Inc. + * Copyright(c) 2011 TJ Holowaychuk + * Copyright(c) 2014 Jonathan Ong + * Copyright(c) 2014-2015 Douglas Christopher Wilson + * MIT Licensed + */ + +'use strict' + +/** + * Module dependencies. + * @private + */ + +var accepts = require('accepts') +var escapeHtml = require('escape-html') +var fs = require('fs') +var path = require('path') +var util = require('util') + +/** + * Module variables. + * @private + */ + +var DOUBLE_SPACE_REGEXP = /\x20{2}/g +var NEW_LINE_REGEXP = /\n/g +var STYLESHEET = fs.readFileSync(path.join(__dirname, '/public/style.css'), 'utf8') +var TEMPLATE = fs.readFileSync(path.join(__dirname, '/public/error.html'), 'utf8') +var inspect = util.inspect +var toString = Object.prototype.toString + +/* istanbul ignore next */ +var defer = typeof setImmediate === 'function' + ? setImmediate + : function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } + +/** + * Error handler: + * + * Development error handler, providing stack traces + * and error message responses for requests accepting text, html, + * or json. + * + * Text: + * + * By default, and when _text/plain_ is accepted a simple stack trace + * or error message will be returned. + * + * JSON: + * + * When _application/json_ is accepted, connect will respond with + * an object in the form of `{ "error": error }`. + * + * HTML: + * + * When accepted connect will output a nice html stack trace. + * + * @return {Function} + * @api public + */ + +exports = module.exports = function errorHandler (options) { + // get environment + var env = process.env.NODE_ENV || 'development' + + // get options + var opts = options || {} + + // get log option + var log = opts.log === undefined + ? env !== 'test' + : opts.log + + if (typeof log !== 'function' && typeof log !== 'boolean') { + throw new TypeError('option log must be function or boolean') + } + + // default logging using console.error + if (log === true) { + log = logerror + } + + return function errorHandler (err, req, res, next) { + // respect err.statusCode + if (err.statusCode) { + res.statusCode = err.statusCode + } + + // respect err.status + if (err.status) { + res.statusCode = err.status + } + + // default status code to 500 + if (res.statusCode < 400) { + res.statusCode = 500 + } + + // log the error + var str = stringify(err) + if (log) { + defer(log, err, str, req, res) + } + + // cannot actually respond + if (res._header) { + return req.socket.destroy() + } + + // negotiate + var accept = accepts(req) + var type = accept.type('html', 'json', 'text') + + // Security header for content sniffing + res.setHeader('X-Content-Type-Options', 'nosniff') + + // html + if (type === 'html') { + var isInspect = !err.stack && String(err) === toString.call(err) + var errorHtml = !isInspect + ? escapeHtmlBlock(str.split('\n', 1)[0] || 'Error') + : 'Error' + var stack = !isInspect + ? String(str).split('\n').slice(1) + : [str] + var stackHtml = stack + .map(function (v) { return '
  • ' + escapeHtmlBlock(v) + '
  • ' }) + .join('') + var body = TEMPLATE + .replace('{style}', STYLESHEET) + .replace('{stack}', stackHtml) + .replace('{title}', escapeHtml(exports.title)) + .replace('{statusCode}', res.statusCode) + .replace(/\{error\}/g, errorHtml) + res.setHeader('Content-Type', 'text/html; charset=utf-8') + res.end(body) + // json + } else if (type === 'json') { + var error = { message: err.message, stack: err.stack } + for (var prop in err) error[prop] = err[prop] + var json = JSON.stringify({ error: error }, null, 2) + res.setHeader('Content-Type', 'application/json; charset=utf-8') + res.end(json) + // plain text + } else { + res.setHeader('Content-Type', 'text/plain; charset=utf-8') + res.end(str) + } + } +} + +/** + * Template title, framework authors may override this value. + */ + +exports.title = 'Connect' + +/** + * Escape a block of HTML, preserving whitespace. + * @api private + */ + +function escapeHtmlBlock (str) { + return escapeHtml(str) + .replace(DOUBLE_SPACE_REGEXP, '  ') + .replace(NEW_LINE_REGEXP, '
    ') +} + +/** + * Stringify a value. + * @api private + */ + +function stringify (val) { + var stack = val.stack + + if (stack) { + return String(stack) + } + + var str = String(val) + + return str === toString.call(val) + ? inspect(val) + : str +} + +/** + * Log error to console. + * @api private + */ + +function logerror (err, str) { + console.error(str || err.stack) +} diff --git a/node_modules/errorhandler/package.json b/node_modules/errorhandler/package.json new file mode 100644 index 0000000..6fd5a21 --- /dev/null +++ b/node_modules/errorhandler/package.json @@ -0,0 +1,80 @@ +{ + "_from": "errorhandler", + "_id": "errorhandler@1.5.0", + "_inBundle": false, + "_integrity": "sha1-6rpkyl1UKjEayUX1gt78M2Fl2fQ=", + "_location": "/errorhandler", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "errorhandler", + "name": "errorhandler", + "escapedName": "errorhandler", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.0.tgz", + "_shasum": "eaba64ca5d542a311ac945f582defc336165d9f4", + "_spec": "errorhandler", + "_where": "C:\\Users\\jonio\\Documents\\Programmieren\\Miniportal\\Neu\\MiniportalAPI", + "bugs": { + "url": "https://github.com/expressjs/errorhandler/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Douglas Christopher Wilson", + "email": "doug@somethingdoug.com" + }, + { + "name": "Jonathan Ong", + "email": "me@jongleberry.com", + "url": "http://jongleberry.com" + } + ], + "dependencies": { + "accepts": "~1.3.3", + "escape-html": "~1.0.3" + }, + "deprecated": false, + "description": "Development-only error handler middleware", + "devDependencies": { + "after": "0.8.2", + "eslint": "3.10.2", + "eslint-config-standard": "6.2.1", + "eslint-plugin-promise": "3.3.2", + "eslint-plugin-standard": "2.0.1", + "istanbul": "0.4.5", + "mocha": "2.5.3", + "supertest": "1.1.0" + }, + "engines": { + "node": ">= 0.8" + }, + "files": [ + "public/", + "LICENSE", + "HISTORY.md", + "index.js" + ], + "homepage": "https://github.com/expressjs/errorhandler#readme", + "license": "MIT", + "name": "errorhandler", + "repository": { + "type": "git", + "url": "git+https://github.com/expressjs/errorhandler.git" + }, + "scripts": { + "lint": "eslint .", + "test": "mocha --reporter spec --bail --check-leaks test/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" + }, + "version": "1.5.0" +} diff --git a/node_modules/errorhandler/public/error.html b/node_modules/errorhandler/public/error.html new file mode 100644 index 0000000..a6d3faf --- /dev/null +++ b/node_modules/errorhandler/public/error.html @@ -0,0 +1,14 @@ + + + + {error} + + + +
    +

    {title}

    +

    {statusCode} {error}

    +
      {stack}
    +
    + + diff --git a/node_modules/errorhandler/public/style.css b/node_modules/errorhandler/public/style.css new file mode 100644 index 0000000..b571e98 --- /dev/null +++ b/node_modules/errorhandler/public/style.css @@ -0,0 +1,35 @@ +* { + margin: 0; + padding: 0; + outline: 0; +} + +body { + padding: 80px 100px; + font: 13px "Helvetica Neue", "Lucida Grande", "Arial"; + background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9)); + background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9); + background-repeat: no-repeat; + color: #555; + -webkit-font-smoothing: antialiased; +} +h1, h2 { + font-size: 22px; + color: #343434; +} +h1 em, h2 em { + padding: 0 5px; + font-weight: normal; +} +h1 { + font-size: 60px; +} +h2 { + margin-top: 10px; +} +ul li { + list-style: none; +} +#stacktrace { + margin-left: 60px; +} diff --git a/package-lock.json b/package-lock.json index 3fa62c5..977f18e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,6 +107,15 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" }, + "errorhandler": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.0.tgz", + "integrity": "sha1-6rpkyl1UKjEayUX1gt78M2Fl2fQ=", + "requires": { + "accepts": "1.3.4", + "escape-html": "1.0.3" + } + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", diff --git a/package.json b/package.json index f4c7498..dfce32c 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "cookie-parser": "^1.4.3", + "errorhandler": "^1.5.0", "express": "^4.16.1", "express-force-ssl": "^0.3.2", "mysql": "^2.15.0",