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


TypeScript InversifyExpressServer.setErrorConfig方法代碼示例

本文整理匯總了TypeScript中inversify-express-utils.InversifyExpressServer.setErrorConfig方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript InversifyExpressServer.setErrorConfig方法的具體用法?TypeScript InversifyExpressServer.setErrorConfig怎麽用?TypeScript InversifyExpressServer.setErrorConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inversify-express-utils.InversifyExpressServer的用法示例。


在下文中一共展示了InversifyExpressServer.setErrorConfig方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: express

export const buildApp = () => {
  const newApp = express();
  newApp.use(bodyParser.json());
  newApp.use(bodyParser.urlencoded({ extended: false }));

  const server = new InversifyExpressServer(container, null, null, newApp);
  server.setErrorConfig((app) => {
    app.use((req: Request, res: Response, next: NextFunction) => {
      res.status(404).send({
        statusCode: 404,
        error: 'Route is not found'
      });
    });

    app.use((err: Error, req: Request, res: Response, next: NextFunction) => handle(err, req, res, next));
  });

  return server.build();
};
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:19,代碼來源:test.app.factory.ts

示例2: function

    exApp.use(helmet());

    exApp.use(session({
        resave: false,
        saveUninitialized: true,
        secret: 'testing',
    }));
    exApp.use(passport.initialize());
    exApp.use(passport.session()); // persistent login sessions

});


// generic Error Handler1
server.setErrorConfig((exApp) => {
    exApp.use(errorHandler);
});

app = server.build();

let passportManagement = kernel.get<PassportMiddleware>(PassportMiddleware.name);

passport.serializeUser(function(user, done) {
    passportManagement.serializeUser(user, done);
});

passport.deserializeUser(async function(id, done) {
    await passportManagement.deserializeUser(id, done);
});

passport.use(new Strategy(
開發者ID:Uter1007,項目名稱:sumobase.core,代碼行數:31,代碼來源:app.fake.ts

示例3: next

  if (
    !req.header('Content-Type') ||
    (req.header('Content-Type') !== 'application/json' && !req.header('Content-Type').includes('application/x-www-form-urlencoded'))
  ) {
    return res.status(406).json({
      error: 'Unsupported "Content-Type"'
    });
  }

  return next();
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

let server = new InversifyExpressServer(container, null, null, app);
server.setErrorConfig((app) => {
  // 404 handler
  app.use((req: Request, res: Response, next: NextFunction) => {
    res.status(404).send({
      statusCode: 404,
      error: 'Route is not found'
    });
  });

  // exceptions handler
  app.use((err: Error, req: Request, res: Response, next: NextFunction) => handle(err, req, res, next));
});

export default server.build();
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:30,代碼來源:app.ts

示例4: MongoStore

    app.use(session({ resave: false,
                      saveUninitialized: true,
                      secret: config.passwordHandler.sessionPw,
                      store: new MongoStore( {mongooseConnection: mongoose.connection})
                    }));

    app.use(passport.initialize());
    app.use(passport.session()); // persistent login sessions

    app.use('/documentation', express.static(__dirname + '/public/documentation/api'));

});

// generic Error Handler1
server.setErrorConfig((app) => {
    app.use(errorHandler);
});

let app = server.build();

// passport configuration
let passportManagement = kernel.get<PassportMiddleware>(PassportMiddleware.name);

passport.serializeUser(function(user, done) {
    passportManagement.serializeUser(user, done);
});

passport.deserializeUser(async function(id, done) {
    await passportManagement.deserializeUser(id, done);
});
開發者ID:Uter1007,項目名稱:sumobase.core,代碼行數:30,代碼來源:app.ts


注:本文中的inversify-express-utils.InversifyExpressServer.setErrorConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。