|
@ -1,6 +1,7 @@ |
|
|
'use strict' |
|
|
'use strict' |
|
|
const path = require('path') |
|
|
const path = require('path') |
|
|
const url = require('url') |
|
|
const url = require('url') |
|
|
|
|
|
const arrayify = require('array-back') |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @module local-web-server |
|
|
* @module local-web-server |
|
@ -50,6 +51,16 @@ function localWebServer (options) { |
|
|
process.env.DEBUG = '*' |
|
|
process.env.DEBUG = '*' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const log = options.log |
|
|
|
|
|
log.options = log.options || {} |
|
|
|
|
|
|
|
|
|
|
|
if (options.verbose && !log.format) { |
|
|
|
|
|
log.format = 'none' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
options.rewrite = arrayify(options.rewrite) |
|
|
|
|
|
options.forbid = arrayify(options.forbid) |
|
|
|
|
|
|
|
|
const debug = require('debug')('local-web-server') |
|
|
const debug = require('debug')('local-web-server') |
|
|
const Koa = require('koa') |
|
|
const Koa = require('koa') |
|
|
const convert = require('koa-convert') |
|
|
const convert = require('koa-convert') |
|
@ -59,17 +70,10 @@ function localWebServer (options) { |
|
|
const bodyParser = require('koa-bodyparser') |
|
|
const bodyParser = require('koa-bodyparser') |
|
|
const mw = require('./middleware') |
|
|
const mw = require('./middleware') |
|
|
|
|
|
|
|
|
const log = options.log |
|
|
|
|
|
log.options = log.options || {} |
|
|
|
|
|
|
|
|
|
|
|
const app = new Koa() |
|
|
const app = new Koa() |
|
|
const _use = app.use |
|
|
const _use = app.use |
|
|
app.use = x => _use.call(app, convert(x)) |
|
|
app.use = x => _use.call(app, convert(x)) |
|
|
|
|
|
|
|
|
if (options.verbose && !log.format) { |
|
|
|
|
|
log.format = 'none' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* CORS: allow from any origin */ |
|
|
/* CORS: allow from any origin */ |
|
|
app.use(cors()) |
|
|
app.use(cors()) |
|
|
|
|
|
|
|
|