lib/serve.js
/**
 * Main server logic
 *
 * @param {object} options The option to configue the server
 * @returns {Promise}
 */
Main server logic
@param {object} options The option to configue the server
@returns {Promise}
Main server logic @param { object } options The option to configue the server @returns { Promise }
async function server (options = {}) {
  const app = new Koa()
  app.use(root(process.env.STUFF_FOLDER_SRC))
  await make({
    output: path.join(process.env.STUFF_FOLDER_SRC, `index.html`),
    format: `html/slides`
  })
  return new Promise((resolve, reject) => {
    const srv = http
      .createServer(app.callback())
      .listen(options.port, (err) => {
        if (err) { return reject(err) }
        const port = srv.address().port
        process.logger.info(_`Access your slides at: http://localhost:${port}`)
        if (options.browser) {
          open(`http://localhost:${port}`)
        }
        resolve(port)
      })
  })
}
async function server ( options = { } ) { const app = new Koa ( ) app . use ( root ( process . env . STUFF_FOLDER_SRC ) ) await make ( { output : path . join ( process . env . STUFF_FOLDER_SRC , ` ` ) , format : ` ` } ) return new Promise ( ( resolve , reject ) => { const srv = http . createServer ( app . callback ( ) ) . listen ( options . port , ( err ) => { if ( err ) { return reject ( err ) } const port = srv . address ( ) . port process . logger . info ( _ ` ${ port } ` ) if ( options . browser ) { open ( ` ${ port } ` ) } resolve ( port ) } ) } ) }
Main server logic
 @param {object} options The option to configue the server
 @returns {Promise}
Main server logic @param { object } options The option to configue the server @returns { Promise }
// Set up our basic static server // We make sure that we have a document to serve // Because http.createServer doesn't provide a Promise based API // we return our own Promise to react to the listen callback. // We need to use http.createServer in order to be able to get back // the port used by our server (especially if the port hasn't been // set explicitely, we have to log it back to the user.). // Koa cannot do this out of the box // When we used a headless browser to generate a PDF document, we // need to get back the port to let the headless browser know where // to navigate.