Socket
Socket
Sign inDemoInstall

serve-static

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-static - npm Package Compare versions

Comparing version 1.11.2 to 1.12.0

18

HISTORY.md

@@ -0,1 +1,19 @@

1.12.0 / 2017-02-5
===================
* Send complete HTML document in redirect response
* Set default CSP header in redirect response
* deps: send@0.15.0
- Fix false detection of `no-cache` request directive
- Fix incorrect result when `If-None-Match` has both `*` and ETags
- Fix weak `ETag` matching to match spec
- Remove usage of `res._headers` private field
- Support `If-Match` and `If-Unmodified-Since` headers
- Use `res.getHeaderNames()` when available
- Use `res.headersSent` when available
- deps: debug@2.6.1
- deps: etag@~1.8.0
- deps: fresh@0.5.0
- deps: http-errors@~1.6.1
1.11.2 / 2017-01-23

@@ -2,0 +20,0 @@ ===================

31

index.js

@@ -145,2 +145,22 @@ /*!

/**
* Create a minimal HTML document.
*
* @param {string} title
* @param {string} body
* @private
*/
function createHtmlDocument (title, body) {
return '<!DOCTYPE html>\n' +
'<html lang="en">\n' +
'<head>\n' +
'<meta charset="utf-8">\n' +
'<title>' + title + '</title>\n' +
'</head>\n' +
'<body>\n' +
'<pre>' + body + '</pre>\n' +
'</body>\n'
}
/**

@@ -163,3 +183,3 @@ * Create a directory listener that just 404s.

function createRedirectDirectoryListener () {
return function redirect () {
return function redirect (res) {
if (this.hasTrailingSlash()) {

@@ -179,4 +199,4 @@ this.error(404)

var loc = encodeUrl(url.format(originalUrl))
var msg = 'Redirecting to <a href="' + escapeHtml(loc) + '">' + escapeHtml(loc) + '</a>\n'
var res = this.res
var doc = createHtmlDocument('Redirecting', 'Redirecting to <a href="' + escapeHtml(loc) + '">' +
escapeHtml(loc) + '</a>')

@@ -186,7 +206,8 @@ // send redirect response

res.setHeader('Content-Type', 'text/html; charset=UTF-8')
res.setHeader('Content-Length', Buffer.byteLength(msg))
res.setHeader('Content-Length', Buffer.byteLength(doc))
res.setHeader('Content-Security-Policy', "default-src 'self'")
res.setHeader('X-Content-Type-Options', 'nosniff')
res.setHeader('Location', loc)
res.end(msg)
res.end(doc)
}
}

9

package.json
{
"name": "serve-static",
"description": "Serve static files",
"version": "1.11.2",
"version": "1.12.0",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",

@@ -12,7 +12,8 @@ "license": "MIT",

"parseurl": "~1.3.1",
"send": "0.14.2"
"send": "0.15.0"
},
"devDependencies": {
"eslint": "3.14.0",
"eslint": "3.16.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-markdown": "1.0.0-beta.3",
"eslint-plugin-promise": "3.4.0",

@@ -33,3 +34,3 @@ "eslint-plugin-standard": "2.0.1",

"scripts": {
"lint": "eslint .",
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --bail --check-leaks test/",

@@ -36,0 +37,0 @@ "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",

@@ -22,2 +22,4 @@ # serve-static

<!-- eslint-disable no-unused-vars -->
```js

@@ -162,3 +164,3 @@ var serveStatic = require('serve-static')

// Set header to force download
function setHeaders(res, path) {
function setHeaders (res, path) {
res.setHeader('Content-Disposition', contentDisposition(path))

@@ -200,2 +202,3 @@ }

var express = require('express')
var path = require('path')
var serveStatic = require('serve-static')

@@ -205,4 +208,4 @@

app.use(serveStatic(__dirname + '/public-optimized'))
app.use(serveStatic(__dirname + '/public'))
app.use(serveStatic(path.join(__dirname, 'public-optimized')))
app.use(serveStatic(path.join(__dirname, 'public')))
app.listen(3000)

@@ -219,2 +222,3 @@ ```

var express = require('express')
var path = require('path')
var serveStatic = require('serve-static')

@@ -224,3 +228,3 @@

app.use(serveStatic(__dirname + '/public', {
app.use(serveStatic(path.join(__dirname, 'public'), {
maxAge: '1d',

@@ -227,0 +231,0 @@ setHeaders: setCustomCacheControl

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc