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
Post a Comment