Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-static

Package Overview
Dependencies
Maintainers
10
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-static - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

6

History.md
4.0.0 / 2017-07-03
==================
* upgrade to koa-send@4
* use async function
3.0.0 / 2016-03-24

@@ -3,0 +9,0 @@ ==================

64

index.js
'use strict';
'use strict'

@@ -8,6 +8,6 @@ /**

const debug = require('debug')('koa-static');
const resolve = require('path').resolve;
const assert = require('assert');
const send = require('koa-send');
const debug = require('debug')('koa-static')
const { resolve } = require('path')
const assert = require('assert')
const send = require('koa-send')

@@ -18,3 +18,3 @@ /**

module.exports = serve;
module.exports = serve

@@ -30,34 +30,40 @@ /**

function serve(root, opts) {
opts = opts || {};
function serve (root, opts) {
opts = opts || {}
assert(root, 'root directory is required to serve files');
assert(root, 'root directory is required to serve files')
// options
debug('static "%s" %j', root, opts);
opts.root = resolve(root);
if (opts.index !== false) opts.index = opts.index || 'index.html';
debug('static "%s" %j', root, opts)
opts.root = resolve(root)
if (opts.index !== false) opts.index = opts.index || 'index.html'
if (!opts.defer) {
return function serve(ctx, next){
if (ctx.method == 'HEAD' || ctx.method == 'GET') {
return send(ctx, ctx.path, opts).then(done => {
if (!done) {
return next();
}
});
return async function serve (ctx, next) {
if (ctx.method === 'HEAD' || ctx.method === 'GET') {
try {
await send(ctx, ctx.path, opts)
} catch (err) {
await next()
}
return
}
return next();
};
await next()
}
}
return function serve(ctx, next){
return next().then(() => {
if (ctx.method != 'HEAD' && ctx.method != 'GET') return;
// response is already handled
if (ctx.body != null || ctx.status != 404) return;
return async function serve (ctx, next) {
await next()
return send(ctx, ctx.path, opts);
});
};
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') return
// response is already handled
if (ctx.body != null || ctx.status !== 404) return // eslint-disable-line
try {
await send(ctx, ctx.path, opts)
} catch (err) {
ctx.status = err.status || 500
}
}
}

@@ -5,3 +5,3 @@ {

"repository": "koajs/static",
"version": "3.0.0",
"version": "4.0.0",
"keywords": [

@@ -18,17 +18,27 @@ "koa",

"devDependencies": {
"istanbul": "0",
"koa": "2",
"mocha": "2",
"supertest": "1"
"eslint": "^4.1.1",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.6.1",
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"istanbul": "^0.4.5",
"koa": "^2.3.0",
"mocha": "^3.4.2",
"supertest": "^3.0.0"
},
"license": "MIT",
"dependencies": {
"debug": "*",
"koa-send": "^3.2.0"
"debug": "^2.6.8",
"koa-send": "^4.1.0"
},
"scripts": {
"lint": "eslint --fix .",
"test": "mocha --harmony --reporter spec",
"test-cov": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha",
"test-travis": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly"
},
"engines": {
"node": ">= 7.6.0"
}
}

@@ -21,4 +21,4 @@ # koa-static

```js
var koa = require('koa');
var app = koa();
const Koa = require('koa');
const app = new Koa();
app.use(require('koa-static')(root, opts));

@@ -37,2 +37,3 @@ ```

- `gzip` Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.
- `extensions` Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`)

@@ -42,5 +43,5 @@ ## Example

```js
var serve = require('koa-static');
var koa = require('koa');
var app = koa();
const serve = require('koa-static');
const Koa = require('koa');
const app = new Koa();

@@ -47,0 +48,0 @@ // $ GET /package.json

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