You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
646 B

  1. 'use strict'
  2. const Koa = require('koa')
  3. const serve = require('koa-static')
  4. const convert = require('koa-convert')
  5. const extend = require('deep-extend')
  6. const serveIndex = require('koa-serve-index')
  7. /**
  8. * @module local-web-server
  9. */
  10. module.exports = getApp
  11. process.on('unhandledRejection', (reason, p) => {
  12. throw reason
  13. })
  14. function getApp (options) {
  15. options = extend({
  16. static: { root: '.' },
  17. serveIndex: { path: '.' }
  18. }, options)
  19. const app = new Koa()
  20. app.use(convert(serve(options.static.root, options.static.options)))
  21. app.use(convert(serveIndex(options.serveIndex.path, options.serveIndex.options)))
  22. return app
  23. }