node.js - get current protocol and host from mongoose virtual method -


i have created simple mongoose schema following

const playlistschema = mongoose.schema({     imagefile: buffer }, {     tojson: {         virtuals: true     } }); 

and have virtual method builds image url depending on current hostname , protocol, like

playlistschema.virtual('image').get(function(){     return protocol + hostname +          process.env.port + '/playlist/' + this._id + '/image'; }); 

as far know hostname , protocol available in req object, not accessible mongoose virtual methods.

is there way implement or it's bad practice , i'm doing wrong?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -