本文整理汇总了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();
});
示例2:
app.use((req: Request, res: Response, next: NextFunction) => {
res.status(404).send({
statusCode: 404,
error: 'Route is not found'
});
});
示例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));
});
示例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).
},
示例5: can
protected can(req: Request, res: Response) {
res.json(req.session.isAdmin ? true : false);
}
示例6: current
protected current(req: Request, res: Response) {
res.json(req.session.username || 'Sign In');
}
示例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'];
//.........这里部分代码省略.........
示例8:
.catch(err =>{
this.log.error(err)
res.json(err)
})
示例9:
ccHelper.emailUs(req).then(s => {res.json(s)});