Browse Source

path blacklist.. etags..

master
Lloyd Brookes 9 years ago
parent
commit
15e0074770
  1. 1
      .travis.yml
  2. 28
      lib/local-web-server.js
  3. 14
      package.json

1
.travis.yml

@ -2,4 +2,3 @@ language: node_js
node_js:
- '5.0'
- '4.2'
- '0.12'

28
lib/local-web-server.js

@ -8,16 +8,14 @@ const morgan = require('koa-morgan')
const compress = require('koa-compress')
const streamLogStats = require('stream-log-stats')
const cors = require('kcors')
const conditional = require('koa-conditional-get');
const etag = require('koa-etag');
/**
* @module local-web-server
*/
module.exports = getApp
process.on('unhandledRejection', (reason, p) => {
throw reason
})
function getApp (options) {
options = Object.assign({
static: {},
@ -26,7 +24,6 @@ function getApp (options) {
compress: false
}, options)
const log = options.log
log.options = log.options || {}
@ -35,6 +32,19 @@ function getApp (options) {
/* CORS: allow from any origin */
app.use(convert(cors()))
/* path blacklist */
app.use(function pathBlacklist (ctx, next) {
if (/css$/.test(ctx.path)) {
ctx.throw(403, 'FUCK NO.')
} else {
return next()
}
})
app.use(convert(conditional()))
app.use(convert(etag()))
/* mime-type overrides */
if (options.mime) {
app.use((ctx, next) => {
return next().then(() => {
@ -47,6 +57,7 @@ function getApp (options) {
})
}
/* compress response */
if (options.compress) {
app.use(convert(compress()))
}
@ -66,9 +77,12 @@ function getApp (options) {
}
if (log.format) app.use(convert(morgan.middleware(log.format, log.options)))
/* serve static files */
if (options.static.root) {
app.use(convert(serve(options.static.root, options.static.options)))
}
/* serve directory index */
if (options.serveIndex.path) {
app.use(convert(serveIndex(options.serveIndex.path, options.serveIndex.options)))
}
@ -82,3 +96,7 @@ function logstalgiaDate () {
.replace('GMT', '')
.replace(' (BST)', '')
}
process.on('unhandledRejection', (reason, p) => {
throw reason
})

14
package.json

@ -7,7 +7,17 @@
},
"main": "lib/local-web-server.js",
"license": "MIT",
"keywords": [ "dev", "server", "web", "tool", "front-end", "development", "cors", "mime", "rest" ],
"keywords": [
"dev",
"server",
"web",
"tool",
"front-end",
"development",
"cors",
"mime",
"rest"
],
"engines": {
"node": ">=4.0.0"
},
@ -28,7 +38,9 @@
"koa": "^2.0.0-alpha.3",
"koa-charset": "^1.1.4",
"koa-compress": "^1.0.8",
"koa-conditional-get": "^1.0.3",
"koa-convert": "^1.1.0",
"koa-etag": "^2.1.0",
"koa-json": "^1.1.1",
"koa-morgan": "^0.4.0",
"koa-rewrite": "^1.1.1",

Loading…
Cancel
Save