implement mime-type overrides.. tests.

This commit is contained in:
Lloyd Brookes
2015-11-13 11:26:02 +00:00
parent b615ffe4e0
commit 69db357661
6 changed files with 48 additions and 34 deletions

View File

@ -1,4 +1,5 @@
'use strict'
const path = require('path')
const Koa = require('koa')
const serve = require('koa-static')
const convert = require('koa-convert')
@ -30,9 +31,19 @@ function getApp (options) {
const app = new Koa()
// app.use((ctx, next) => {
// return next().then(() => ctx.type = 'text/plain')
// })
// CORS
if (options.mime) {
app.use((ctx, next) => {
return next().then(() => {
const reqPathExtension = path.extname(ctx.path).slice(1)
Object.keys(options.mime).forEach(mimeType => {
const extsToOverride = options.mime[mimeType]
if (extsToOverride.indexOf(reqPathExtension) > -1) ctx.type = mimeType
})
})
})
}
if (options.compress) {
app.use(convert(compress()))