How to use the restify.acceptParser 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 xiezefan / EasyIM-Android / server / server.js View on Github external
*/
var restify = require('restify');
var passport = require('passport');
var Config = require('./config/server-config');
var Auth = require('./common/auth-helper');

var User = require('./routes/users');
var Message = require('./routes/messages');

var server = restify.createServer({
    name: Config.name,
    versions: Config.versions
});

server.use(restify.pre.userAgentConnection());
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(passport.initialize());
passport.use(Auth.UserAuthorization);

// static files
server.get(/^\/((.*)(\.)(.+))*$/, restify.serveStatic({ directory: 'public', default: "index.html" }));

server.post('/test', passport.authenticate('basic', { session: false }), function (req, res, next) {
    console.log("header: " + JSON.stringify(req.headers));
    console.log("User: " + req.user);
    console.log(JSON.stringify(req.body));

    // validate
    res.json({ content: 'success' });
    next();
github joyent / sdc-adminui / lib / adminui.js View on Github external
}

    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;
    var sdcClients = require('./sdc-clients').createClients(config);
    var self = this;
github Azure-Samples / active-directory-node-webapi / node-server / app.js View on Github external
// 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
server.use(restify.authorizationParser()); // Looks for authorization headers

// Let's start using Passport.js

server.use(passport.initialize()); // Starts passport
server.use(passport.session()); // Provides session support

/**
/*
/* Calling the OIDCBearerStrategy and managing users
github AzureADQuickStarts / AppModelv2-WebAPI-nodejs / node-server / app.js View on Github external
// 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
server.use(restify.authorizationParser()); // Looks for authorization headers

// Let's start using Passport.js

server.use(passport.initialize()); // Starts passport
server.use(passport.session()); // Provides session support

var bearerStrategy = new OIDCBearerStrategy(options,
    function(token, done) {
        log.info(token, 'was the token retreived');
github AzureAD / passport-azure-ad / examples / server-oauth2 / server.js View on Github external
// 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
server.use(restify.authorizationParser()); // Looks for authorization headers

// Let's start using Passport.js

server.use(passport.initialize()); // Starts passport
server.use(passport.session()); // Provides session support

/**
/*
/* Calling the OIDCBearerStrategy and managing users
github bryanpaluch / jsep-to-sip-gw / test / test_endpoints / http.js View on Github external
function HttpEndpoint(opts){
  this.port = opts.port || 9000;
  this.role = opts.role || 'answerer';
  this.server = restify.createServer({
    name: 'http-endpoint'
  });
  this.server.use(restify.acceptParser(this.server.acceptable));
  this.server.use(restify.queryParser());
  this.server.use(restify.bodyParser({mapParams: false}));
  this.server.post('/session/:uuid', this.controller.bind(this));
  this.registeredUsers = {};
  this.sessions = {};
}
github crystian / WEBAPP-BUILDER / templates / angular-full / www / api / api.js View on Github external
var restify = require('restify');

var server = restify.createServer({
	name: 'myapp',
	version: '1.0.0'
});
server.use(restify.CORS());
server.use(restify.acceptParser(server.acceptable));
//server.use(restify.queryParser());
//server.use(restify.bodyParser());

server.get('/echo/:name', function (req, res, next) {
	res.send(req.params);
	return next();
});

server.listen(9005, function () {
	console.log('%s listening at %s', server.name, server.url);
});
github bryanpaluch / jsep-to-sip-gw / server.js View on Github external
var restify = require('restify'),
    JSEPGateway = require('./lib/jsep-to-sip'),
    request = require('request'),
    logger = require('./lib/logwinston');

var env = process.env.NODE_ENV || 'development';
var config = require('./config/conftool').getConf();
var server = restify.createServer({
    name: 'jsep-to-sip-gateway',
      version: '0.0.1'
});

require('./lib/registrar_db').connect();


server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser({mapParams: false}));

var jsepSession = require('./controllers/session');
var user = require('./controllers/user');

//inbound calls
server.post('/session', jsepSession.create);
server.put('/session/:uuid', jsepSession.add);
server.del('/session/:uuid', jsepSession.remove);


//registration
server.post('/registration', user.register);

server.listen(config.httpport, function () {
github misterpah / Haxe-Studio / bin / js / restify-server.js View on Github external
(function(){
hs_server.use(restify.acceptParser(hs_server.acceptable));
hs_server.use(restify.queryParser());
hs_server.use(restify.bodyParser());

var isPortTaken = function(port, fn) {
  var net = require('net')
  var tester = net.createServer()
  .once('error', function (err) {
    if (err.code != 'EADDRINUSE') return fn(err)
    fn(null, true)
  })
  .once('listening', function() {
    tester.once('close', function() { fn(null, false) })
    .close()
  })
  .listen(port)
}
github phodal / freerice / server / app.js View on Github external
var restify         = require('restify');
var server          = restify.createServer();

var Authenticate    = require('./service/authenticate');
var auth            = new Authenticate();

var DBService        = require('./service/account_service');
var get_response    = new DBService();

var Rice            = require('./service/rice_service');
var rice            = new Rice();

server.use(restify.gzipResponse());
server.use(restify.bodyParser());
server.use(restify.acceptParser(['json', 'application/json']));
server.use(
    function crossOrigin(req,res,next){
        'use strict';
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "X-Requested-With");
        return next();
    }
);

server.get('/all/account', get_response.findAllAccount);
server.get('/account/id/:id', get_response.getAccountById);
server.get('/account/name/:name', get_response.getAccountByName);

server.post('/account/create', auth.create);
server.post('/login/user', auth.login);