Skip to content

🐛 .documents: Documented API missing #526

@perguth

Description

@perguth

This a 🐛 bug report.

.documents is not accepting an object as second parameter even though it's documented in the README.

Expected Behavior

var someState = { render: 'me' }

// Documented API:
// `compiler.documents(routename, [opts], done(err, { buffer, hash }))`
compiler.documents('/', {
  state: someState
}, noop)

// Render the document passing `state` to the render function.

Current Behavior

uncaughtException { AssertionError [ERR_ASSERTION]: 'object' == 'function'
    at Bankai.documents (/application/node_modules/bankai/index.js:172:10)
    at Server.http.createServer (/application/server.js:107:17)
    at Server.emit (events.js:189:13)
    at parserOnIncoming (_http_server.js:676:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
  generatedMessage: true,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: 'object',
  expected: 'function',
  operator: '==' }

Possible Solution

Maybe build on #446?

Context

I would like to just prerender the document instead of letting the client wait to receive it's initial state via WebSockets.

Code Sample

const server = http.createServer((request, response) => {
  if (request.url === '/') {
    compilerCli.documents('/', { state }, (error, node) => {
      response.setHeader('content-type', 'text/html')
      gzip(node.buffer, request, response)
    })
  }
  compilerHtml(request, response, function () {
    response.statusCode = 404
    response.end('not found')
  })
})

Your Environment

Software Version(s)
Choo 6.13.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions