本文整理匯總了TypeScript中express.Request.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Request.get方法的具體用法?TypeScript Request.get怎麽用?TypeScript Request.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Request
的用法示例。
在下文中一共展示了Request.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getUser
function getUser(request: Request): Result<User> {
let result: Result<User> = new ResultBasic<User>();
let username = request.get('username');
let password = request.get('password');
userService.getUserByUserame(username)
.onSuccess((user: User) => {
result.success(user);
})
.onError((err: any) => {
result.error(err);
});
return result;
}
示例2: return
return (req: Request, res: Response, next: Function) : void => {
let requestEnd = res.end;
let requestedUrl: string = url.parse(req.originalUrl);
let startTime: Date = new Date();
let userAgent: string = req.get('User-Agent');
res.end = (chunk?: any, encoding?: any) : void => {
let time: Date = new Date();
let data = {
'statusCode': res.statusCode,
'method': req.method,
'responseTime': time.getTime() - startTime.getTime(),
'url': req.originalUrl,
requestedUrl,
'ip': req.headers['x-forwarded-for'] || req.ip,
'userAgent': userAgent,
'language': req.query.lang || lang
};
res.end = requestEnd;
res.end(chunk, encoding);
logr.info('', data);
};
next();
};
示例3: async
router.post('/', async (req: Request, res: Response, next: NextFunction) => {
let label = req.body.label || '';
label = label.replace(/[^a-zA-Z0-9-\.\/ ]/, '');
if (label === '') {
label = useragent.parse(req.get('user-agent')).toString();
}
const persist = [true, '1', 'true'].indexOf(req.body.persist) > -1;
const token = new Token(label, persist);
await db.addTokens(req.user, [token]);
const cookieOptions: CookieOptions = {
path: req.app.locals.config.get('NOTIFIER_BASE_URL'),
};
if (token.persist) {
cookieOptions.expires = new Date(Date.now() + (86400000 * 30));
}
res.cookie('token', `${token.key},${token.value}`, cookieOptions);
res.format({
'application/json': () => res.json({
key: token.key,
value: token.value,
}),
'default': () => res.status(406).send('Not Acceptable'),
'text/plain': () => res.send(`${token.key},${token.value}`),
});
next();
});
示例4: url
public async url(req: Request, res: Response) {
const url = req.get('host') + req.originalUrl;
const settings = this.settings.generator.urls.find((o) => o.url.endsWith(url));
if (settings) {
if (!(await this.isEnabled())) {
return res.status(412).send({ error: 'Highlights system is disabled' });
} else {
if (!(await global.cache.isOnline())) {
return res.status(412).send({ error: 'Stream is offline' });
} else {
if (settings.clip) {
const cid = await global.api.createClip({ hasDelay: false });
if (!cid) { // Something went wrong
return res.status(403).send({ error: 'Clip was not created!'});
}
}
if (settings.highlight) {
this.main({ parameters: '', sender: null });
}
return res.status(200).send({ ok: true });
}
}
} else {
return res.status(404).send({ error: 'Unknown highlights link' });
}
}
示例5: verifyUrl
verifyUrl(req: Request, addressReader?: Types.AddressReader): Types.VerifyResult {
const url = req.protocol+'://'+req.get('host')+req.url;
if( url.length < 33 || !this.verifyString( url.substring(0, url.length-32), url.substr(-32) ) ) {
return Types.VerifyResult.blackholed;
}
// get signed data
let lastAmpPos = url.lastIndexOf('&signed=');
if(lastAmpPos == -1) {
lastAmpPos = url.lastIndexOf('?signed=');
}
if(lastAmpPos == -1) {
return Types.VerifyResult.blackholed;
}
const data = querystring.parse( url.substring(lastAmpPos+8, url.length-33), ';', ':');
req.url = url.substr(0, lastAmpPos);
// check additional conditions
if(data.a && addressReader && data.a != addressReader(req)) {
return Types.VerifyResult.blackholed;
}
if(data.m && data.m.indexOf(req.method) == -1) {
return Types.VerifyResult.blackholed;
}
if(data.e && data.e < Math.ceil(+new Date()/1000)) {
return Types.VerifyResult.expired;
}
return Types.VerifyResult.ok;
}
示例6: getRequestUrl
export function getRequestUrl(req: Request) {
return url.format({
protocol: req.protocol,
host: req.get('host'),
pathname: req.path,
search: querystring.stringify(req.query)
});
}
示例7: getRawValue
protected getRawValue(request: Request): any {
const cookies = request.get('cookie');
if (!cookies) {
return undefined;
}
const cookie = cookies
.split(';')
.map(o => new CookieHelper(o.trim()))
.filter(o => o.name === this.name)[0];
return cookie ? cookie.value : undefined;
}
示例8: return
return (req: Request, res: Response, next: RequestHandler) => {
res.set('OData-Version', '4.0');
var data = this.document(format)
if (!data['@odata.context']) {
var url = req.protocol + '://' + req.get('host') + req.originalUrl.split("?").shift();
if(url.slice(-1) !== '/') url += '/'
data['@odata.context'] = url + '$metadata';
}
res.json(data);
};
示例9: renderWithClientToken
function renderWithClientToken(template: string, req: Request, res: Response) {
const token = shortid.generate();
db.saveToken({
date: new Date(),
token,
ip: req.ip,
userAgent: req.get('User-Agent')
});
res.render(template, {
clientToken: token,
layout: false,
});
}
示例10: index
index(req: Request, res: Response ) {
const originUrl = req.protocol && req.get('host') ? req.protocol + '://' + req.get('host') : 'http://localhost:3000';
const baseRef: string = req.baseUrl && req.baseUrl !== '' ? req.baseUrl : '/';
const expressConfig : ExpressEngineConfig = {
req,
res,
ngModule: MainModule,
originUrl: originUrl,
baseUrl: baseRef,
requestUrl: req.url || baseRef,
preboot: false
};
res.render('index', expressConfig);
}