How to use the restify.plugins 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 howdyai / botkit / packages / botbuilder-adapter-slack / examples / multiteam.js View on Github external
// Import required bot services. See https://aka.ms/bot-services to learn more about the different part of a bot
const { MemoryStorage, ConversationState, UserState, TurnContext } = require('botbuilder');
const { BotConfiguration } = require('botframework-config');

const { SlackAdapter, SlackEventMiddleware, SlackIdentifyBotsMiddleware } = require('../lib/slack_adapter');

// Read botFilePath and botFileSecret from .env file
// Note: Ensure you have a .env file and include botFilePath and botFileSecret.
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });

// Create HTTP server
let server = restify.createServer();
server.use(restify.plugins.bodyParser({ mapParams: false }));
server.use(restify.plugins.queryParser());
server.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log(`\n${ server.name } listening to ${ server.url }`);
    console.log(`\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator`);
});

// .bot file path
const BOT_FILE = path.join(__dirname, (process.env.botFilePath || ''));

let botConfig;
try {
    // Read bot configuration from .bot file.
    botConfig = BotConfiguration.loadSync(BOT_FILE, process.env.botFileSecret);
} catch (err) {
    console.error(`\nError reading bot file. Please ensure you have valid botFilePath and botFileSecret set for your environment.`);
    console.error(`\n - The botFileSecret is available under appsettings for your Azure Bot Service bot.`);
    console.error(`\n - If you are running this bot locally, consider adding a .env file with botFilePath and botFileSecret.\n\n`);
github pnp / PnP / Solutions / O365.Modern.Provisioning / VeronicaBot / app.js View on Github external
/*-----------------------------------------------------------------------------------------
Veronica Bot - makes use of Microsoft Graph in order to store the users's request in a list 
Author: Giuliano De Luca (MVP Office Development) - Twitter @giuleon
Date: February 20, 2018
-----------------------------------------------------------------------------------------*/

var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
var request = require("request");
var Q = require('q');

// Setup Restify Server
var server = restify.createServer();

server.use(restify.plugins.bodyParser({
  mapParams: true
})); // To be able to get the authorization code (req.params.code)

server.listen(process.env.port || process.env.PORT || 3978, function () {
  console.log('%s listening to %s', server.name, server.url);
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
  appId: process.env.MicrosoftAppId,
  appPassword: process.env.MicrosoftAppPassword,
});

// Config
var config = {
  'clientId': process.env.AAD_CLIENT_ID, // The client Id retrieved from the Azure AD App
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 54.teams-task-module / index.js View on Github external
// Create HTTP server.
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log(`\n${ server.name } listening to ${ server.url }`);
});

// Listen for incoming requests.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
    });
});

// Serve static pages from the 'pages' folder.
server.get('/*', restify.plugins.serveStatic({
    directory: './pages'
}));
github vperrinfr / BotBuilder-Watson / app.js View on Github external
function findOrCreateContext (convId){
      // Let's see if we already have a session for the user convId
    if (!contexts)
        contexts = [];
        
    if (!contexts[convId]) {
        // No session found for user convId, let's create a new one
        //with Michelin concervsation workspace by default
        contexts[convId] = {workspaceId: workspace, watsonContext: {}};
        //console.log ("new session : " + convId);
    }
return contexts[convId];
}

server.get(/\/?.*/, restify.plugins.serveStatic({
  directory: './images',
  default: 'Picture1.png'
}))
github microsoft / BotFramework-WebChat / samples / 20.a.upload-to-azure-storage / web / src / index.js View on Github external
'AZURE_STORAGE_ACCOUNT_NAME',
  'AZURE_STORAGE_CONTAINER_NAME',
  'DIRECT_LINE_SECRET'
].forEach(name => {
  if (!process.env[name]) {
    throw new Error(`Environment variable ${name} must be set.`);
  }
});

const { join } = require('path');
const restify = require('restify');

const server = restify.createServer();
const { PORT, STATIC_FILES } = process.env;

server.use(restify.plugins.queryParser());

// Registering routes.
server.get('/api/azurestorage/uploadsastoken', require('./routes/azureStorage/uploadSASToken'));
server.get('/api/directline/token', require('./routes/directLine/token'));
server.post('/api/messages', require('./routes/botMessages'));

// We will use the REST API server to serve static web content to simplify deployment for demonstration purposes.
STATIC_FILES &&
  server.get(
    '/**/*',
    restify.plugins.serveStatic({
      default: 'index.html',
      directory: join(__dirname, '..', STATIC_FILES)
    })
  );
github eps1lon / poe-db / src / server / createServer.js View on Github external
// mkdirp workaround
  createCacheDir();

  const server = restify.createServer({
    name: 'mypoedb',
    version: '1.0.0',
  });

  // enable cors, see https://github.com/restify/node-restify/issues/296
  server.use(cors());
  server.opts('/.*/', (req, res, next) => {
    res.send(200);
    return next();
  });

  server.use(restify.plugins.acceptParser(server.acceptable));
  server.use(restify.plugins.queryParser());
  server.use(restify.plugins.bodyParser());

  if (process.env.NODE_ENV === 'production') {
    require('./enhanceServer.prod')(server);
  } else {
    require('./enhanceServer.dev')(server);
  }

  // custom middleware
  server.use(exposeGameVersion);

  mountRoutes(server, models);

  return server;
};
github YouTransfer / YouTransfer / app.js View on Github external
// YouTransfer
var youtransfer = require('./lib/youtransfer');
var passport = require('./lib/passport');
var routes = require('./lib/routes');
var middleware = require('./lib/middleware');
var errors = require('./lib/errors');

// ------------------------------------------------------------------------------------------ App Initialization

var app = restify.createServer(); 
app.pre(restify.pre.sanitizePath());
app.use(restify.plugins.bodyParser({ 
	mapParams: true,
	multiples: true 
}));
app.use(restify.plugins.queryParser());
app.use(restify.cookieParser.parse);
app.use(restify.compression());
app.use(restify.cookieSession({
	name: 'session',
	secret: nconf.get('ENCRYPTIONKEY') || 'NotSoVerySecretCookieKey',
	expires: new Date().add({ minutes: 20 }),
	secure: (nconf.get('NODE_ENV') == "production"),
	maxAge: 1200000
}));

app.use(errors);
app.use(middleware);
app.use(passport.initialize());
app.use(passport.session());

// ------------------------------------------------------------------------------------------ App Routing
github jones2000 / HQChart / umychart_indexapi / hqchartapi.js View on Github external
var JSIndexController=require('./jsindexcontroller').JSIndexController;
var config=require('./hqchartconfig').Config;

if (!config) config={ Port:18080 };

if (config.Monogdb && config.Monogdb.Url)
{
  JSIndexController.SetMongodb(config.Monogdb);

  console.log('[HQChartApi] load index script from mongo .....');
  JSIndexController.LoadIndex();
}

//JSCommonComplier.JSComplier.SetDomain('http://100.114.65.219');
var server = restify.createServer({name:'HQChart.testserver'});
server.use(restify.plugins.bodyParser());   //支持json post
server.use(restify.plugins.fullResponse()); //跨域
server.use(restify.plugins.gzipResponse()); //支持压缩

server.post('/api/jsindex',JSIndexController.Post);
server.post('/api/reloadindex',JSIndexController.ReloadIndex);
server.get('/api', homepage);

function homepage(req, res, next)
{
  res.send(200,{message: 'homepage'});
  return next();
}

console.log(`[HQChartApi] Start server Port=${config.Port} ......`);
server.listen(config.Port, function() 
{
github Yoctol / bottender / examples / custom-server-restify / server.js View on Github external
app.prepare().then(() => {
  const server = restify.createServer();

  server.use(restify.plugins.queryParser());
  server.use(restify.plugins.bodyParser());

  server.get('/api', (req, res) => {
    res.send({ ok: true });
  });

  server.get('*', (req, res) => {
    return handle(req, res);
  });
  server.post('*', (req, res) => {
    return handle(req, res);
  });

  server.listen(port, err => {
    if (err) throw err;
    console.log(`> Ready on http://localhost:${port}`);
github alexwarth / roomdb / src / listen.js View on Github external
function listen(port = 8080) {
  const db = this;
  const server = restify.createServer({name: 'RoomDB'});
  server.use(restify.plugins.queryParser());

  const cors = corsMiddleware({origins: ['*']});
  server.pre(cors.preflight);
  server.use(cors.actual);

  server.get('/facts', (req, res, next) => {
    try {
      if (req.query.query !== undefined) {
        const patterns = JSON.parse(req.query.query);
        const solutions = db.select(...patterns);
        res.send(solutions);
        next();
      } else {
        res.send(db.getAllFacts());
        next();
      }