當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript express.Response類代碼示例

本文整理匯總了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;未經允許,請勿轉載。