當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript restify.queryParser函數代碼示例

本文整理匯總了TypeScript中restify.queryParser函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript queryParser函數的具體用法?TypeScript queryParser怎麽用?TypeScript queryParser使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了queryParser函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => any): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    let out = log(JSON.parse(req.query['msg']));
    res.send(out);
    return next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
    maxAge: 0,
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
    maxAge: 0,
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
    maxAge: 0,
  }));

  // Show errors. This should be a Restify default.
  server.on('uncaughtException', (req: any, res: any, route: any, err: any) => {
    if (err.stack) {
      console.error(err.stack);
    } else {
      console.error(err);
    }
  });

  // More filling in the blanks: log each request as it comes in.
  server.on('after', (req: any, res: any, route: any, err: any) => {
    plog(res.statusCode + " " + req.method + " " + req.url);
  });

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
開發者ID:Microsoft,項目名稱:staticstaging,代碼行數:58,代碼來源:harness.ts

示例2: constructor

    constructor(name: string) {
        this.router = Restify.createServer({
            name: name
        });

        this.router.on('listening', () => {
            log.debug(`${this.router.name} listening on ${this.router.url}`);
        });

        this.router.use(Restify.acceptParser(this.router.acceptable));
        this.router.use(stripEmptyBearerToken);
        this.router.use(Restify.dateParser());
        this.router.use(Restify.queryParser());
    }
開發者ID:kpreeti096,項目名稱:BotFramework-Emulator,代碼行數:14,代碼來源:restServer.ts

示例3: bootstrap

  public bootstrap(port: number) {
    this.restifyApplication.use(restify.CORS());
    this.restifyApplication.use(restify.pre.sanitizePath());
    this.restifyApplication.use(restify.acceptParser(this.restifyApplication.acceptable));
    this.restifyApplication.use(restify.bodyParser());
    this.restifyApplication.use(restify.queryParser());
    this.restifyApplication.use(restify.authorizationParser());
    this.restifyApplication.use(restify.fullResponse());

    // configure API and error routes
    this.restifyContactRouter.configApiRoutes(this.restifyApplication);
    this.restifyContactRouter.configErrorRoutes(this.restifyApplication);
    // listen on provided ports
    this.restifyApplication.listen(port, () => {
      console.log("%s listening at %s", this.restifyApplication.name, this.restifyApplication.url);
    });
  }
開發者ID:rajajhansi,項目名稱:aspnetcore-aurelia-tutorial,代碼行數:17,代碼來源:restify-application.ts

示例4: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => void): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    log(JSON.parse(req.query['msg']));
    res.send('done');
    next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
  }));

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
開發者ID:kleopatra999,項目名稱:staticstaging,代碼行數:41,代碼來源:harness.ts

示例5: function

import * as restify from 'restify';

import app from './app';
import config from './config';
//創建http server
let server: restify.Server = restify.createServer({
    name: 'docs-search_server'
});
server.use(restify.gzipResponse());//gzip壓縮
server.use(restify.bodyParser());//將post請求的body數據轉化到req.params
server.use(restify.queryParser());//將url?後的參數轉化到req.params
// server.get(/\/docs\/public\/?.*/, restify.serveStatic({
//     directory: '../public'
// }));
//http服務器錯誤捕捉
// server.on('err', function (err) {
//     mongoose.disconnect(function (err) {
//         console.log('mongoose was disconnected');
//     });
//     console.log('server has a error, and stoped');
// });

//開始監聽
server.listen(config.API_PORT, function () {
    console.log("%s listening at %s", server.name, server.url);
});
app(server);
開發者ID:snippetmodule,項目名稱:docs-search-client,代碼行數:27,代碼來源:www.ts

示例6: function

import * as restify from "restify";
import * as routes from "./routes";

//config
export const server = restify.createServer({
    name: 'myAPI',
    version: '1.0.0'
});

//parsing settings
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.pre(restify.pre.sanitizePath());

//call the routes.ts file for available REST API routes
console.log('setting routes...');
routes.setRoutes(server);

//when running the app will listen locally to port 51234
server.listen(51234, function() {
    console.log('%s listening at %s', server.name, server.url);
})

開發者ID:jeffhollan,項目名稱:typescriptRestifyAPI,代碼行數:23,代碼來源:app.ts

示例7: startServer

function startServer(configuration:model.Configuration, database:any) {

    var Q = require('q');

    var restify = require("restify");
    var server = restify.createServer({name: "zander"})
        .pre(restify.pre.sanitizePath())
        .use(restify.fullResponse())
        .use(restify.bodyParser())
        .use(restify.authorizationParser())
        .use(restify.requestLogger())
        .use(restify.queryParser());

    if (configuration.throttle)
        server.use(restify.throttle(configuration.throttle));

    var datas = new data.DataFactory(configuration, database);
    var services = new service.ServiceFactory(datas);
    var controllers = new controller.ControllerFactory(configuration, services);
    var validators = new validate.ValidatorFactory();

    function addController(path:string, controller:any) {

        console.log("Register " + controller.constructor.name + " to path " + path);

        function createControllerRequestHandler(method:(r:model.HttpRequest) => Q.IPromise<model.HttpResponse>) {
            return function (request:any, response:any, next:any) {
                var httpRequest:model.HttpRequest = new model.HttpRequest();
                httpRequest.authorization = request.authorization;
                httpRequest.headers = request.headers;
                httpRequest.parameters = request.params;
                httpRequest.body = request.body;
                httpRequest.log = request.log;
                httpRequest.query = request.query;

                method(httpRequest)
                    .then((httpResponse:model.HttpResponse) => {
                        httpResponse.content !== null
                            ? response.send(httpResponse.statusCode, httpResponse.content)
                            : response.send(httpResponse.statusCode);
                    }, (e) => {
                        request.log.error(e);
                        response.send(500, { "code": "InternalServerError" })
                    });
                return next();
            };
        }

        var httpMethods = ["get", "head", "post", "put", "patch", "del"];

        // For each of these HTTP methods, if the controller has the function with the same name then bind the
        // function and handler so that it will be invoked on such a request on path
        httpMethods
            .filter(function (x:string) {
                return controller[x] !== undefined;
            })
            .forEach(function (x:string) {
                var minAuthLevel = controller[x + "AuthLevel"] || model.AuthenticationLevel.None;
                var validator : string = controller[x + "Validator"];
                var authoriser : string = controller[x + "Authoriser"];
                console.log("Register " + x + " to path " + path + " with min authentication level " + minAuthLevel);

                server[x](path, createControllerRequestHandler((request:model.HttpRequest):Q.IPromise<model.HttpResponse> => {
                    var actualRequest = (request:model.HttpRequest):Q.IPromise<model.HttpResponse> => {
                        if (validator) {
                            var result = validators.get(validator).apply(request);
                            if (!result.success) {
                                return Q(new model.HttpResponse(400, {
                                    "code": "BadRequest",
                                    "message": result.reason
                                }));
                            }
                        }

                        if (!authoriser)
                            return controller[x](request);

                        return services.authorisers.get(authoriser)
                            .authenticate(request.user, request.parameters.target)
                            .then((authorised:service.AuthorisationResult) => {
                                switch (authorised) {
                                    case service.AuthorisationResult.NotFound:
                                        return Q(new model.HttpResponse(404, { "code": "ResourceNotFound", "message": "Resource Not Found" }));

                                    case service.AuthorisationResult.Failure:
                                        return Q(new model.HttpResponse(403, { "code": "Forbidden" }));

                                    case service.AuthorisationResult.Success:
                                        return controller[x](request);
                                }
                            });
                    };
                    return services.authenticate.atLeast(minAuthLevel, request, actualRequest);
                }));
            });
    }

    addController("/verify", controllers.verify);
    addController("/user/", controllers.users);
    addController("/user/:target", controllers.user);
//.........這裏部分代碼省略.........
開發者ID:MorleyDev,項目名稱:zander.server,代碼行數:101,代碼來源:server.ts

示例8: BookStoreController

let port = 3000;
let bsController = new BookStoreController(new BookStore());
let serverController = new ServerController();
let redirectController = new RedirectController();

var server = createServer({
  formatters: {
    'application/json': function (req, res, body, cb) {
      return cb(null, saveStringify(body));
    }
  }
});
server.use(bodyParser());
server.use(CORS({}));
server.use(queryParser());


server.get('/swagger.json', serverController.getFixedSwaggerJson.bind(serverController));

// serve redirects
server.get(/^\/(a\/|avatar\/)/, redirectController.avatarRedirect.bind(redirectController));
server.get(/^\/(app|bm|it|ngh|start|two|cover|quotes|b\/|x\/)/, redirectController.redirect.bind(redirectController));

// serve public folder
server.get(/^(?!\/(book|info)).*/, serveStatic({
  directory: __dirname + '/public/',
  default: 'index.html'
}));

// API routes
開發者ID:Angular2Buch,項目名稱:book-monkey2-api,代碼行數:30,代碼來源:server.ts


注:本文中的restify.queryParser函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。