question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How might I access `ctx` outside of a middleware or a route?

See original GitHub issue

I’m trying to implement socket.io to my app, and I want to have it work like sailsjs has, where you can do req.socket.emit or w/e.

I’m trying to add io to the ctx variable so that I could do something like

ctx.io.emit('hello', "Hello!");

But I can’t seem to find how to access ctx without binding the io to it in every single middleware request (only really needs to be a one time thing). Any information would be great thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PanicIsRealcommented, Apr 20, 2016

Sorry one more quick thing, is the app.context client specific, or will all connected people share the same clisock until a new one connects, or does each app.context have their own clisock

0reactions
tjcommented, Apr 20, 2016

Each request receives a new ctx but that object inherits app.context, so it’ll be a shared clisock. Which for reference is here: https://github.com/koajs/koa/blob/master/lib/application.js#L134-L167

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gofiber how to get the original path in middleware
I've checked the code, you can access the original path with ctx.Route().Path : package main import ( "fmt" "github.com/gofiber/fiber/v2" ) ...
Read more >
define middleware - ThinkJS
The function returns ctx , next , and ctx is a shorthand for context , which is an object of the current request's...
Read more >
without-ctx-next - Go Packages
Package main is a simple example of the behavior change of the execution flow of the handlers, normally we need the `ctx.
Read more >
API — Flask Documentation (2.2.x)
API¶. This part of the documentation covers all the interfaces of Flask. For parts where Flask depends on external libraries, we document the...
Read more >
Context Methods - Iris
try to access to handler's Context response writer. ... Controllers can accept middleware(s) from the MVC's Application's Router as normally.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found