How might I access `ctx` outside of a middleware or a route?
See original GitHub issueI’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:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry one more quick thing, is the
app.context
client specific, or will all connected people share the sameclisock
until a new one connects, or does eachapp.context
have their ownclisock
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