Sailsjs - How to get the current request outside the controller

I am wondering how to access req / res outside of the scope of the controller in the sails.js file.

I am writing a helper (sort of a service) that would need to access req

it without sending it as a parameter, so somehow I need it as a global value.

+3


source to share


1 answer


NodeJS Domains can do what you are looking for. You can create a middleware / policy that creates a new one domain

for each request and sets the req object as a property in domain

. Then you can just access the property from the object domain

.



However, it looks like a code smell. You might want to look at converting your service to Class

and just create it with req

. Then you can just pass service

to your code.

0


source







All Articles