本文整理匯總了TypeScript中express.Express.route方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Express.route方法的具體用法?TypeScript Express.route怎麽用?TypeScript Express.route使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Express
的用法示例。
在下文中一共展示了Express.route方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: init
export function init (app: Express) {
app
.route("/foro")
.get( foro.findTema )
.post(passport.authenticate("jwt", { session: false }), security.validateAdminRole, foro.update );
app
.route("/foro/:tema_id")
.get( foro.getOneTema );
}
示例2: searchRoutes
/** REST endpoints for the search feature. */
function searchRoutes(app: Express, db) {
app.route('/api/search/:terms')
.get(search);
const aqlQuery = require('arangojs').aqlQuery;
/**
* Endpoint to search users, parties and questions.
*
* Example:
* GET /api/search/:terms
* {
* "users": [ ... ],
* "parties": [ ... ],
* "questions": [ ... ]
* }
*/
function search(req: Request, res: Response): void {
const terms = req.params.terms;
db.query(aqlQuery`
return {
users: (
for u in user
filter like(u._key, ${ terms }, true)
or like(u.email, ${ terms }, true)
or like(u.name, concat('%', ${ terms }, '%'), true)
or like(u.nickname, concat('%', ${ terms }, '%'), true)
limit 5
return keep(u, '_key', 'name', 'nickname')
),
parties: (
for p in party
filter like(p._key, ${ terms }, true)
or like(p.name, concat('%', ${ terms }, '%'), true)
limit 5
return keep(p, '_key', 'name')
),
questions: (
for q in question
filter like(q.title, concat('%', ${ terms }, '%'), true)
limit 5
return keep(q, '_key', 'title')
)
}
`)
.then(cursor => cursor.all())
.then(values => values.length ?
res.json(values[0]) :
res.sendStatus(404)
)
.catch(err => sendError(err, res));
}
}
示例3: locationRoutes
/** REST endpoints for location management. */
function locationRoutes(app: Express, db) {
app.route('/api/location')
.get(get);
const aqlQuery = require('arangojs').aqlQuery;
/**
* Endpoint to serch locations. It requires 2 query parameters: `lvl` and `qry`.
* Lvl 0 searches for countries, 1 = states, 2 = cities.
*
* Example:
* GET /api/location?lvl=1&qry=san
* [
* { "_key": "ES", "name": "Espírito Santo, Brasil" },
* { "_key": "SC", "name": "Santa Catarina, Brasil" }
* ]
*/
function get(req: Request, res: Response): void {
db.query(aqlQuery`
for v in union_distinct (
for v,e,p in ${+ req.query.lvl} outbound document('location/BR')
graph 'worldGraph'
sort v.name
filter like(v.name, concat(${req.query.qry}, '%'), true)
return merge(p.vertices[-1], { name:
concat_separator(', ', reverse(p.vertices[*].name))
}),
for v,e,p in ${+ req.query.lvl} outbound document('location/BR')
graph 'worldGraph'
sort v.name
filter like(v.name, concat('%', ${req.query.qry}, '%'), true)
return merge(p.vertices[-1], { name:
concat_separator(', ', reverse(p.vertices[*].name))
})
)
limit 5
return v
`)
.then(cursor => cursor.all())
.then(values => values.length ?
res.json(values) :
res.sendStatus(404)
)
.catch(err => sendError(err, res));
}
}
示例4: userRoutes
/** REST endpoints for user management. */
function userRoutes(app: Express, db) {
app.route('/api/user/:username/follow')
.post(follow)
.delete(unfollow);
app.route('/api/user/:username/upsert')
.post(upsert);
app.route('/api/user/:username')
.get(get)
.patch(patch);
const aqlQuery = require('arangojs').aqlQuery;
/**
* Endpoint to select a user by its given username.
*
* Example:
* GET /api/user/andre
*/
function get(req: Request, res: Response): void {
const myself = aqlQuery`
let period = date_subtract(date_now(), 'P1W')
for me in user
filter me._id == ${req['user']._id}
let followers = first(
for v in 1 inbound me graph 'socialGraph'
collect with count into followers
return followers
),
following = first(
for v in 1 outbound me graph 'socialGraph'
collect with count into following
return following
),
myAnswers = (
for q, a in 1 outbound me graph 'qaGraph'
sort a.updatedAt desc
limit 12
return merge (
keep(q, '_key', 'title'),
{ when: a.updatedAt }
)
),
newAnswers = (
for u, f in 1 outbound me graph 'socialGraph'
for q, a in 1 outbound u graph 'qaGraph'
filter a.updatedAt > period
collect who = {_key: u._key, name: (u.nickname || u.name)},
action = 'ANSWERED'
into group = a.updatedAt
return {
who, action,
questions: count(group),
when: max(group)
}
),
newFollowers = (
for u, f in 1 inbound me graph 'socialGraph'
filter f.updatedAt > period
return {
who: {_key: u._key, name: (u.nickname || u.name)},
action: 'FOLLOWED',
when: f.updatedAt
}
),
news = (
for news in union(newAnswers, newFollowers)
sort news.when desc
limit 12
return news
)
return merge(
me,
{ me: true, followers, following, news, myAnswers }
)
`;
const notMyself = aqlQuery`
for u in user
filter u._key == ${req.params.username}
let followed = 0 < length(
for f in follow
filter f._from == ${req['user']._id} and f._to == u._id
return 1
),
affinity = (
for u2 in [u, ${ req['user']._id }]
for v, e in 1 outbound u2 graph 'qaGraph'
collect question = {_key: v._key, title: v.title} into answers = e.chosen
filter count(answers) == 2 // questions answered by both users
let match = sum(answers) != 1 ? 1 : 0 // flags same answer by both users
return {question, match}
)
return merge(u, {
me: false,
followed,
agree: affinity[* filter CURRENT.match == 1 return CURRENT.question],
//.........這裏部分代碼省略.........