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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -