keystonejs/keystone-classic

Provide hostname etc from request to schemaplugins and hooks

Open

#3,187 opened on Jul 21, 2016

View on GitHub
 (8 comments) (0 reactions) (0 assignees)JavaScript (2,288 forks)batch import
help wantedneeds input

Repository metrics

Stars
 (14,656 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

I need to write a mongoose plugin. where I need a Request object to find hostname.

module.exports = exports = function(schema, options) {
    schema.add({
        hostname: String
    })

    schema.pre('save', true, function(next, done) {
        this.hostname = req.headers.host; //need request object
        next();
        setTimeout(done, 100);
    });
}

I have raised related question in stackoverflow

Contributor guide