implement mime-type overrides.. tests.
This commit is contained in:
@ -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()))
|
||||
|
Reference in New Issue
Block a user