demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/serve-static-1.15.0/index.js

Path
demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/serve-static-1.15.0/index.js
Status
scanned
Type
file
Name
index.js
Extension
.js
Programming language
JavaScript
Mime type
text/html
File type
HTML document, ASCII text
Tag

      
    
Rootfs path

      
    
Size
4570 (4.5 KB)
MD5
3707f8d6ee2c6d88ffab23c0c4f1509b
SHA1
1245000610229e2f79a8ffa95a40b08242371db0
SHA256
768d6407e86ba974e7b8a0e79625e76a932b1f2503207c87f871fcf98be21b1e
SHA512

      
    
SHA1_git
b7d3984c447992f39583ddf4d8ecf01ffbb5b6db
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
index.js | 4.5 KB |

/*! * serve-static * Copyright(c) 2010 Sencha Inc. * Copyright(c) 2011 TJ Holowaychuk * Copyright(c) 2014-2016 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var encodeUrl = require('encodeurl') var escapeHtml = require('escape-html') var parseUrl = require('parseurl') var resolve = require('path').resolve var send = require('send') var url = require('url') /** * Module exports. * @public */ module.exports = serveStatic module.exports.mime = send.mime /** * @param {string} root * @param {object} [options] * @return {function} * @public */ function serveStatic (root, options) { if (!root) { throw new TypeError('root path required') } if (typeof root !== 'string') { throw new TypeError('root path must be a string') } // copy options object var opts = Object.create(options || null) // fall-though var fallthrough = opts.fallthrough !== false // default redirect var redirect = opts.redirect !== false // headers listener var setHeaders = opts.setHeaders if (setHeaders && typeof setHeaders !== 'function') { throw new TypeError('option setHeaders must be function') } // setup options for send opts.maxage = opts.maxage || opts.maxAge || 0 opts.root = resolve(root) // construct directory listener var onDirectory = redirect ? createRedirectDirectoryListener() : createNotFoundDirectoryListener() return function serveStatic (req, res, next) { if (req.method !== 'GET' && req.method !== 'HEAD') { if (fallthrough) { return next() } // method not allowed res.statusCode = 405 res.setHeader('Allow', 'GET, HEAD') res.setHeader('Content-Length', '0') res.end() return } var forwardError = !fallthrough var originalUrl = parseUrl.original(req) var path = parseUrl(req).pathname // make sure redirect occurs at mount if (path === '/' && originalUrl.pathname.substr(-1) !== '/') { path = '' } // create send stream var stream = send(req, path, opts) // add directory handler stream.on('directory', onDirectory) // add headers listener if (setHeaders) { stream.on('headers', setHeaders) } // add file listener for fallthrough if (fallthrough) { stream.on('file', function onFile () { // once file is determined, always forward error forwardError = true }) } // forward errors stream.on('error', function error (err) { if (forwardError || !(err.statusCode < 500)) { next(err) return } next() }) // pipe stream.pipe(res) } } /** * Collapse all leading slashes into a single slash * @private */ function collapseLeadingSlashes (str) { for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) !== 0x2f /* / */) { break } } return i > 1 ? '/' + str.substr(i) : str } /** * Create a minimal HTML document. * * @param {string} title * @param {string} body * @private */ function createHtmlDocument (title, body) { return '<!DOCTYPE html> ' + '<html lang="en"> ' + '<head> ' + '<meta charset="utf-8"> ' + '<title>' + title + '</title> ' + '</head> ' + '<body> ' + '<pre>' + body + '</pre> ' + '</body> ' + '</html> ' } /** * Create a directory listener that just 404s. * @private */ function createNotFoundDirectoryListener () { return function notFound () { this.error(404) } } /** * Create a directory listener that performs a redirect. * @private */ function createRedirectDirectoryListener () { return function redirect (res) { if (this.hasTrailingSlash()) { this.error(404) return } // get original URL var originalUrl = parseUrl.original(this.req) // append trailing slash originalUrl.path = null originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + '/') // reformat the URL var loc = encodeUrl(url.format(originalUrl)) var doc = createHtmlDocument('Redirecting', 'Redirecting to <a href="' + escapeHtml(loc) + '">' + escapeHtml(loc) + '</a>') // send redirect response res.statusCode = 301 res.setHeader('Content-Type', 'text/html; charset=UTF-8') res.setHeader('Content-Length', Buffer.byteLength(doc)) res.setHeader('Content-Security-Policy', "default-src 'none'") res.setHeader('X-Content-Type-Options', 'nosniff') res.setHeader('Location', loc) res.end(doc) } }
Detected license expression
mit
Detected license expression (SPDX)
MIT
Percentage of license text
0.43
Copyrights
- end_line: 3
  copyright: Copyright (c) 2010 Sencha Inc.
  start_line: 3
- end_line: 4
  copyright: Copyright (c) 2011 TJ Holowaychuk
  start_line: 4
- end_line: 5
  copyright: Copyright (c) 2014-2016 Douglas Christopher Wilson
  start_line: 5
Holders
- holder: Sencha Inc.
  end_line: 3
  start_line: 3
- holder: TJ Holowaychuk
  end_line: 4
  start_line: 4
- holder: Douglas Christopher Wilson
  end_line: 5
  start_line: 5
Authors

      
    
License detections License expression License expression SPDX
mit-4e7803e6-e54b-c9ca-bcd2-bee9755c0dd7 mit MIT
Package URL License Primary language
pkg:npm/acme-demo-app@1.0.0 JavaScript
pkg:npm/serve-static@1.15.0 mit JavaScript