Skip to content

Context.locals is undefined #84

@dannluciano

Description

@dannluciano

Description

Server not setup ctx.locals

const server = require('server')

const {get, error} = server.router
const {status} = server.reply

server(
  ctx => { ctx.locals.username = 'franciscop' },
  get('/', ctx => `Username is: ${ctx.locals.username}`),
  error(ctx => status(500).send(ctx.error.message))
)

Expected outcome

When I access http://localhost:3000/ I should get:

Username is: franciscop

Actual outcome

But when I access http://localhost:3000/ I got:

Cannot set property 'username' of undefined

Live Demo

Example: https://glitch.com/edit/#!/join/17c45851-d9ac-4e98-a912-305f8e4b4dc6

System Information

OS: Windows 10

Node Version: v8.9.4

Server.js Version: 1.0.18

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions