本文整理汇总了TypeScript中express.Response类的典型用法代码示例。如果您正苦于以下问题:TypeScript Response类的具体用法?TypeScript Response怎么用?TypeScript Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: next
app.use((req: PivotRequest, res: Response, next: Function) => {
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
next();
});
开发者ID:avenger-teamave,项目名称:pivot,代码行数:5,代码来源:app.ts
示例2:
app.use((req: Request, res: Response, next: NextFunction) => {
res.status(404).send({
statusCode: 404,
error: 'Route is not found'
});
});
开发者ID:Norestlabs-Mariya,项目名称:backend-ico-dashboard,代码行数:6,代码来源:test.app.factory.ts
示例3:
app.use((err: any, req: Request, res: Response, next: Function) => {
res.status(err.status || 500);
res.send(errorLayout({ version: VERSION, title: 'Error' }, err.message));
});
开发者ID:avenger-teamave,项目名称:pivot,代码行数:4,代码来源:app.ts
示例4: directory
getIndex2:(req:Request, res:Response)=>{
res.send('Hello world....'); //Compiles the file named "index" in the views directory (`/views`) using the view engine (Jade).
},
开发者ID:SaurabhLpRocks,项目名称:trackme,代码行数:3,代码来源:homeController.ts
示例5: can
protected can(req: Request, res: Response) {
res.json(req.session.isAdmin ? true : false);
}
开发者ID:apache,项目名称:helix,代码行数:3,代码来源:user.ts
示例6: current
protected current(req: Request, res: Response) {
res.json(req.session.username || 'Sign In');
}
开发者ID:apache,项目名称:helix,代码行数:3,代码来源:user.ts
示例7: describe
describe('express tooling', () => {
const loggerMock = undefined;
const createRequestMock = (scopes: String[]): Request => ({
get: (name: string) => name,
$$tokeninfo: {
scope: scopes
}
} as any as Request);
const createResponseMock = (): Response => ({
sendStatus: sinon.spy((status: string) => undefined)
} as any as Response);
describe('requireScopesMiddleware', () => {
it('should reject request with 403 if required scopes are not met', (done) => {
// given
const next = sinon.spy();
const requestMock = createRequestMock(['uid', 'test']);
const responseMock = createResponseMock();
const requiredScopes = ['uid', 'test', 'additional'];
// when
requireScopesMiddleware(requiredScopes)(requestMock, responseMock, next);
// then
setTimeout(() => {
expect(responseMock.sendStatus).to.have.been.calledWith(403);
done();
});
});
it('should not call next() if required scopes are not met', (done) => {
// given
const next = sinon.spy();
const requestMock = createRequestMock(['uid', 'test']);
const requiredScopes = ['uid', 'test', 'additional'];
// when
requireScopesMiddleware(requiredScopes)(requestMock, createResponseMock(), next);
// then
setTimeout(() => {
// tslint:disable-next-line
expect(next).to.not.have.been.called;
done();
});
});
it('should call #next if required scopes are met', (done) => {
// given
const next = sinon.spy();
const requestMock = createRequestMock(['uid', 'test']);
const requiredScopes = ['uid', 'test'];
// when
requireScopesMiddleware(requiredScopes)(requestMock, createResponseMock(), next);
// then
setTimeout(() => {
// tslint:disable-next-line
expect(next).to.have.been.called;
done();
});
});
it('should call #next also if user has a superset of the required scopes', (done) => {
// given
const next = sinon.spy();
const requestMock = createRequestMock(['uid', 'test', 'additionalScope']);
const requiredScopes = ['uid', 'test'];
// when
requireScopesMiddleware(requiredScopes)(requestMock, createResponseMock(), next);
// then
setTimeout(() => {
// tslint:disable-next-line
expect(next).to.have.been.called;
done();
});
});
it('should call #next if precedence function returns true', (done) => {
// given
const next = sinon.spy();
const requestMock = createRequestMock(['uid']);
const requiredScopes = ['test'];
//.........这里部分代码省略.........
开发者ID:zalando-incubator,项目名称:lib-oauth-tooling,代码行数:101,代码来源:require-scopes-middleware.ts
示例8:
.catch(err =>{
this.log.error(err)
res.json(err)
})
开发者ID:Lumenss,项目名称:testing-app,代码行数:4,代码来源:EmailController.ts
示例9:
ccHelper.emailUs(req).then(s => {res.json(s)});
开发者ID:bbachi,项目名称:Angular5Sample,代码行数:1,代码来源:cc.controller.ts
注:本文中的express.Response类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论