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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -