本文整理汇总了TypeScript中restify.plugins.queryParser方法的典型用法代码示例。如果您正苦于以下问题:TypeScript plugins.queryParser方法的具体用法?TypeScript plugins.queryParser怎么用?TypeScript plugins.queryParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类restify.plugins
的用法示例。
在下文中一共展示了plugins.queryParser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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());
});
示例2:
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
}
}
}));
server.use(restify.plugins.conditionalHandler([{
示例3: 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();
});
//.........这里部分代码省略.........