How to use the restify.requestLogger function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / active-directory-node-webapi / node-server / app.js View on Github external
var server = restify.createServer({
    name: "Windows Azure Active Directroy TODO Server",
    version: "2.0.1"
});

// Ensure we don't drop data on uploads
server.pre(restify.pre.pause());

// Clean up sloppy paths like //todo//////1//
server.pre(restify.pre.sanitizePath());

// Handles annoying user agents (curl)
server.pre(restify.pre.userAgentConnection());

// Set a per request bunyan logger (with requestid filled in)
server.use(restify.requestLogger());

// Allow 5 requests/second by IP, and burst to 10
server.use(restify.throttle({
    burst: 10,
    rate: 5,
    ip: true,
}));

// Use the common stuff you probably want
server.use(restify.acceptParser(server.acceptable));
server.use(restify.dateParser());
server.use(restify.queryParser());
server.use(restify.gzipResponse());
server.use(restify.bodyParser({
    mapParams: true
})); // Allows for JSON mapping to REST
github joyent / s3-manta-bridge / lib / bridge_server.js View on Github external
let mantaClient = MantaClientFactory.create(options);
        let router = new Routes(options, mantaClient);
        let authenticator = new Authenticator(options);

        let server = mod_restify.createServer({
            name: 's3-manta-bridge',
            version: apiVersion,
            log: log,
            formatters: {
                'application/xml': xmlFormatter.formatter
            }
        });

        server.use(mod_restify.queryParser());
        server.use(mod_restify.acceptParser(server.acceptable));
        server.use(mod_restify.requestLogger());

        if (options.authEnabled !== false) {
            server.use(authenticator.authenticate.bind(authenticator));
        }

        server.use(function requestPreprocess(req, res, next) {
            /* We normalize paths and bucket names across different request types
             * below. We do this because clients like s3cmd will send requests to
             * the server in the format of /bucket/directory/object when the
             * server is not being accessed via a subdomain. When it is being
             * accessed as a subdomain the path is in the format of
             * /directory/object. This causes a fair bit of complexity if it is
             * not preemptively normalized. */

            // Attach sanitized path to all requests for easy access
            let unencoded = decodeURI(req.path());
github aprnd / asset-server / asset-server.js View on Github external
function setupServer(app) {
    //app.use(restify.dateParser(60)); // not used at the moment
    //app.use(restify.gzipResponse()); // gzip is broken with content-length set in restify
    //app.use(restify.acceptParser(httpServer.acceptable));
    //app.use(restify.queryParser());
    //app.use(restify.fullResponse()); // Respond with full headers
    //app.use(restify.bodyParser()); // Parse full body
    //app.use(restify.authorizationParser()); // Parse auth info manually
    app.use(restify.requestLogger({stream:winstonStream})); // Use winston to log restify
    app.use(restify.throttle({
      burst: config.throttle.burst,
      rate: config.throttle.rate,
      ip: true
    }));

    app.use(restify.conditionalRequest());
    app.use(addConfigurationToRequest);

    /**
     *
     *  Routes
     *
     */

    // POST route to create buckets
github restify / node-restify / examples / todoapp / lib / server.js View on Github external
log: options.log,
        name: 'todoapp',
        version: '1.0.0'
    });

    // Ensure we don't drop data on uploads
    server.pre(restify.pre.pause());

    // Clean up sloppy paths like //todo//////1//
    server.pre(restify.pre.sanitizePath());

    // Handles annoying user agents (curl)
    server.pre(restify.pre.userAgentConnection());

    // Set a per request bunyan logger (with requestid filled in)
    server.use(restify.requestLogger());

    // Allow 5 requests/second by IP, and burst to 10
    server.use(
        restify.throttle({
            burst: 10,
            rate: 5,
            ip: true
        })
    );

    // Use the common stuff you probably want
    server.use(restify.plugins.acceptParser(server.acceptable));
    server.use(restify.plugins.dateParser());
    server.use(restify.plugins.authorizationParser());
    server.use(restify.plugins.queryParser());
    server.use(restify.plugins.gzipResponse());
github joyent / sdc-docker / lib / docker.js View on Github external
res.header('x-response-time', t);

            // DOCKER-617: Set a server version to be compatible with docker.
            // As the docker/docker tests require this header.
            res.header('Server', fmt('Triton/%s (linux)',
                                    constants.SERVER_VERSION));
        });

        req.app = self;
        req.backend = self.backend;
        req.wfapi = self.wfapi;

        next();
    });

    server.use(restify.requestLogger());

    server.use(function (req, res, next) {
        req.trace = trace_event.createBunyanTracer({
            log: req.log
        });
        if (req.route) {
            request_seq_id = (request_seq_id + 1) % 1000;
            req.trace.seq_id = (req.time() * 1000) + request_seq_id;
            req.trace.begin({name: req.route.name, req_seq: req.trace.seq_id});
        }
        next();
    });
    server.on('after', function (req, res, route, err) {
        if (route) {
            req.trace.end({name: route.name, req_seq: req.trace.seq_id});
        }
github joyent / s3-manta-bridge / lib / server.js View on Github external
function BridgeServer(options) {
    var router = require('./router')(options);
    var auth = require('./authentication')(options);

    var server = mod_restify.createServer({
        name: 's3-manta-bridge',
        version: '1.0.0',
        log: options.log,
        formatters: {
            'application/xml': xmlFormatter.formatter
        }
    });

    server.use(mod_restify.queryParser());
    server.use(mod_restify.acceptParser(server.acceptable));
    server.use(mod_restify.requestLogger());

    if (options.authEnabled !== false) {
        server.use(auth.authenticate);
    }

    server.use(function defaultHeaders(req, res, next) {
        res.once('header', function () {
            res.setHeader('Server', 'AmazonS3');
        });
        next();
    });

    /* Pass these variables in the global config so that it is universally
     * available from within all handlers. */
    server.options = options;
    server.options.mantaClient = mantaClient;
github mozilla / telemetry-server / coordinator / coordinator.js View on Github external
function complete_task_by_id(req, res, next) {
  // TODO: reset retries_remaining, claimed_until
  return finish_task_by_id(req, res, next, "Completing", "completed");
}

function publish_task_by_id(req, res, next) {
  return finish_task_by_id(req, res, next, "Publishing", "published");
}

var server = restify.createServer({
  name: "Telemetry Coordinator",
});
server.use(restify.bodyParser());
server.use(restify.queryParser({ mapParams: false }));
server.use(restify.requestLogger());
// TODO: list endpoints at /api (or /doc or whatever)
server.post('/files', get_filtered_files);
server.get('/files', get_filtered_files);
server.post('/tasks', create_task);
server.get('/tasks/:name', get_task_info_by_name)
server.get('/tasks/:name/:task_id', get_task_info)
server.post('/claim/:status', claim_task_by_status)
server.post('/claim/:status/:name', claim_task_by_name)
server.post('/claim/:status/:name/:task_id', claim_task_by_id)
server.post('/release/:task_id', unclaim_task_by_id)
server.post('/kill/:task_id', kill_task_by_id)
server.post('/complete/:task_id', complete_task_by_id)
server.post('/publish/:task_id', publish_task_by_id)

server.listen(8080, function() {
  log.info('%s listening at %s', server.name, server.url)
github joyent / sdc-adminui / lib / adminui.js View on Github external
var pem = fs.readFileSync(DEFAULT_SSL_CERT, 'ascii');
        cert = pem;
        key = pem;
    }

    var server = restify.createServer({
        name: 'adminui',
        log: log,
        certificate: cert,
        key: key
    });

    server.root = this.root;
    server.pre(restify.pre.pause());
    server.pre(restify.pre.sanitizePath());
    server.use(restify.requestLogger());
    server.use(restify.queryParser());
    server.use(restify.gzipResponse());
    server.use(restify.acceptParser(server.acceptable));
    server.use(paramsTrimmer);

    TraceEvent.mount({
        skipRoutes: ['ping', 'getca'],
        server: server
    });

    if (config.simulateLatency) {
        server.use(require('./fake-latency').simulateLatency());
    }

    // Mounts the SDC clients to req.sdc
    config.log = log;
github eclipse / winery / org.eclipse.winery.workflowmodeler / mock / server.js View on Github external
* information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
 * which is available at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
 *******************************************************************************/

var restify = require("restify");
var partition = require("./partition/index");

var server = restify.createServer();
server.use(restify.queryParser());
server.use(restify.requestLogger());
server.use(restify.bodyParser());
server.listen(8889, function () {
    console.log("Mock Server is Started at 8889!!!");
});
partition(server);
github joyent / node-workflow / lib / api.js View on Github external
path: JOB_CANCEL_PATH,
        version: '0.1.0'
    };
    var JOB_RESUME_PATH = JOB_PATH + '/resume';
    var JOB_RESUME_ROUTE = {
        path: JOB_RESUME_PATH,
        version: '0.1.0'
    };

    var PING_PATH = '/ping';
    var PING_ROUTE = {
        path: PING_PATH,
        version: '0.1.0'
    };

    server.use(restify.requestLogger());

    var EVT_SKIP_ROUTES = {
        'getping010': true
    };
    server.use(function (req, res, next) {
        req.trace = trace_event.createBunyanTracer({
            log: req.log
        });
        if (!EVT_SKIP_ROUTES[req.route.name]) {
            req.trace.begin(req.route.name);
        }
        next();
    });
    server.on('after', function (req, res, route, err) {
        if (req.route && !EVT_SKIP_ROUTES[req.route.name]) {
            req.trace.end(req.route.name);