本文整理汇总了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);
});
});
}
示例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());
}
示例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);
});
}
示例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);
});
});
}
示例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);
示例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);
})
示例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);
//.........这里部分代码省略.........
示例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