当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript restify.plugins类代码示例

本文整理汇总了TypeScript中restify.plugins的典型用法代码示例。如果您正苦于以下问题:TypeScript plugins类的具体用法?TypeScript plugins怎么用?TypeScript plugins使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了plugins类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

server.on('after', (req: restify.Request, res: restify.Response, route: restify.Route, err: any) => {
    route.method === 'GET';
    route.name === 'routeName';
    route.path === '/some/path';
    route.path === /\/some\/path\/.*/;
    restify.plugins.auditLogger({ event: 'after', log: logger })(req, res, route, err);
});
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:7,代码来源:restify-tests.ts

示例2: function

bot.setup().then(() => {

    // Listen to activities sent to the bot
    const server = restify.createServer();
    server.use(restify.plugins.queryParser());
    server.listen(process.env.port || process.env.PORT || 3977, function () {
        console.log('%s listening to %s', server.name, server.url);
    });
    server.post('/api/messages', connector.listen());
});
开发者ID:magencio,项目名称:UberBotNode_V3,代码行数:10,代码来源:app.ts

示例3:

server.opts(/(.*)/, send);

server.name = "";
server.versions = [""];
server.acceptable = ["test"];
server.url = "";
server.server = new http.Server();

server.address().port;
server.address().family;
server.address().address;

server.listen("somePath", send);
server.close();

server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.authorizationParser());
server.use(restify.plugins.dateParser());
server.use(restify.plugins.queryParser());
server.use(restify.plugins.jsonp());
server.use(restify.plugins.gzipResponse());
server.use(restify.plugins.bodyParser());
server.use(restify.plugins.throttle({
    burst: 100,
    rate: 50,
    ip: true,
    overrides: {
        '192.168.1.1': {
            rate: 0,
            burst: 0
        }
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:31,代码来源:restify-tests.ts

示例4: Number

import * as restify from 'restify';
import { IProduct, products } from './products';

const server: restify.Server = restify.createServer();
const port: number = 3000;

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

server.get('/api/products', (request: restify.Request, response: restify.Response) => {
  console.log(products);
  response.json(products);
});

server.get('/api/products/:id', (request: restify.Request, response: restify.Response) => {
  const id = Number(request.params.id);
  const product = products.filter(product => product.id === id);
  response.json(product);
});

server.post('/api/products', (request: restify.Request, response: restify.Response) => {
  const newProduct: IProduct = request.body;
  products.push(newProduct);
  response.json(products);
});

server.listen(port, () => console.info(`REST API is running on port ${port}`));
开发者ID:marley-js,项目名称:Mastering-TypeScript-Programming-Techniques,代码行数:26,代码来源:app.ts

示例5: crossOrigin

'use strict';

import * as vscode from 'vscode';
import * as opn from 'opn';
import * as fs from 'fs';
import * as path from 'path';
import * as restify from 'restify';

const server = restify.createServer();
const PORT = 4567;

server.use(restify.plugins.queryParser());
server.use(
    function crossOrigin(req,res,next){
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With");
      return next();
    }
);

server.listen(PORT, () => {
    console.log(`Extension server online on port ${PORT}`);
})

// Serve the bot content.
server.get('/', restify.plugins.serveStatic({
    'directory': `${__dirname}/bot`,
    'default': 'bot.html'
}));

// Opens URLs.
开发者ID:thieskek,项目名称:BotFramework-Samples,代码行数:31,代码来源:extension.ts

示例6: create

export function create(config: any, callback?: () => void) {

    console.log ('Setup server at ' + config);

    let server = restify.createServer();

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

    // Make it a web server
    server.get('/', (req, res, next) => {
        res.redirect('./public/test.html', next);
    });


    server.get('/api/v1.0/reminders', async (req, res, next) => {
        let reminders = await remindersStore.find("j@s.c");
        res.send(reminders);
        return next();
    });

    server.post('/api/v1.0/reminders', async (req, res, next) => {
        let user = "j@s.c";
        req.body['user'] = user;
        let reminder = new reminders.Reminder(req.body);
        let update = await remindersStore.update(reminder);
        res.header("Location", `/api/v1.0/reminders/${reminder.id}`);
        res.send(201, reminder);
        next();
    });

    server.get('/api/v1.0/reminders/:id', async (req, res, next) => {
        let user = "j@s.c";
        if (!req.params.hasOwnProperty('id') || typeof req.params.id != "string") {
            res.send(400, "id not found");
            next();
            return;
        }
        let result = await remindersStore.get(req.params.id);
        if (!result) {
            res.send(404, "Not found.");
        } else {
            res.send(result);
        }
        next();
    });

    server.put('/api/v1.0/reminders/:id', async (req, res, next) => {
        let user = "j@s.c";
        req.body.user = user;
        if (!req.params.hasOwnProperty('id') && typeof req.params.id != "string") {
            res.send(400, "id not found");
            next();
            return;
        }
        let reminder = new reminders.Reminder(req.body, true);
        let exists = await remindersStore.get(req.params.id);
        let update = await remindersStore.update(reminder);
        res.header("Location", `/api/v1.0/reminders/${reminder.id}`);
        res.send(exists ? 200 : 201, reminder);
        next();
    });

    server.patch('/api/v1.0/reminders/:id', async (req, res, next) => {
        let user = "j@s.c";
        if (!req.params.hasOwnProperty('id') && typeof req.params.id != "string") {
            res.send(400, "id not found");
            next();
            return;
        }
        let reminder = await remindersStore.get(req.params.id);
        let created = false;
        if (!reminder) {
            created = true;
            let result = null;
            reminder = new reminders.Reminder(req.body, true);
        } else {
            reminder.update(req.body);
        }
        let update = await remindersStore.update(reminder);
        res.send(created ? 201 : 200, reminder);
        next();
    });

    server.del('/api/v1.0/reminders/:id', async (req, res, next) => {
        let user = "j@s.c";
        if (!req.params.hasOwnProperty('id') && typeof req.params.id != "string") {
            res.send(400, "id not found");
            next();
            return;
        }
        let reminder = await remindersStore.get(req.params.id);
        if (!reminder) {
            res.send(401, "Not found")
        } else {
            await remindersStore.delete(reminder);
            res.send(200);
        }
        next();
    });
//.........这里部分代码省略.........
开发者ID:johnshew,项目名称:nagbot,代码行数:101,代码来源:server.ts

示例7: require

import {createServer, plugins} from 'restify';
import corsMiddleware = require('restify-cors-middleware');

import {deleteSingle} from './delete-single';
import {getAll} from './get-all';
import {getSingle} from './get-single';
import {post} from './post';

var server = createServer();

// Add bodyParser plugin for parsing JSON in request body
server.use(plugins.bodyParser());

// Add CORS
const options: corsMiddleware.Options = {
    preflightMaxAge: 5,
    origins: ['*'],
    allowHeaders: ['API-Token'],
    exposeHeaders: ['API-Token-Expiry']
  };
const cors: corsMiddleware.CorsMiddleware = corsMiddleware(options);
server.pre(cors.preflight);
server.use(cors.actual);

// Add routes
server.get('/api/customers', getAll);
server.post('/api/customers', post);
server.get('/api/customers/:id', getSingle);
server.del('/api/customers/:id', deleteSingle);

server.listen(8080, () => console.log('API is listening'));
开发者ID:,项目名称:,代码行数:31,代码来源:


注:本文中的restify.plugins类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。