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


TypeScript swagger-express-mw.create函數代碼示例

本文整理匯總了TypeScript中swagger-express-mw.create函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript create函數的具體用法?TypeScript create怎麽用?TypeScript create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: require

'use strict';
import express = require('express');
let saggerExpress = require('swagger-express-mw');
let swaggerUi = require('swagger-tools/middleware/swagger-ui');
let app: express.Application = express();
let bodyParser = require('body-parser');
import config = require('./config/config');
import db = require('./api/db/index');

module.exports = app; // for testing

app.use(bodyParser.json());

db.connect();
require('./api/models/index');

saggerExpress.create({appRoot: __dirname}, (err: any, se: any) => {
  if (err) { throw err; }

  app.use(swaggerUi(se.runner.swagger));

  // install middleware
  se.register(app);

  app.listen(config.get('server.port'), () => {
    console.log('Server listening to localhost:' + config.get('server.port'));
  });

});
開發者ID:vmishevski,項目名稱:quiz-node,代碼行數:29,代碼來源:app.ts

示例2: function

swaggerExpress.create(swaggerConfig, function (err, swagger) {
  if (err) { throw err; }


  app.use(function (req, res, next) {
    next();
  });

  app.use(cors(corsOptions));
  swagger.register(app);

  app.get(
    '/auth/google',
    passport.authenticate('google', {
      session: false,
      scope: [
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email',
      ],
    }),
  );

  app.get('/auth/google/callback',
    function (req, res, next) {
      passport.authenticate('google', {
        session: false,
        failureRedirect: api.helpers.Config.settings.ui_base_path,
      },
        function (error, user: api.models.UserModel, info) {
          if (error) { return next(error); }
          if (!user) { return res.redirect(api.helpers.Config.settings.ui_base_path); }
          try {
            let token = jwtService.signToken(user);
            // to prevent from csrf attack we sent back a XSRF-TOKEN in a cookie
            res.cookie('XSRF-TOKEN', token.xsrf, { maxAge: 900000, httpOnly: false });
            res.cookie('JWT-TOKEN', token.jwt, { maxAge: 900000, httpOnly: true });
            let isAdmin = 'false';
            if (user.roles && user.roles.indexOf('admin') > -1) {
              isAdmin = 'true';
            }
            return res.redirect(`${api.helpers.Config.settings.ui_base_path}/#/login?user_id=${user.id}&is_admin=${isAdmin}`);
          } catch (err) {
            return next(err);
          }
        })(req, res, next);
    });

  app.listen(port);

  if (swagger.runner.swagger.paths['/hello']) {
    console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
  }
});
開發者ID:arandehkharghani,項目名稱:tforex-gateway,代碼行數:53,代碼來源:app.ts

示例3: require

import * as SwaggerExpress from "swagger-express-mw";
import express = require("express");

const app = express();
const config: SwaggerExpress.Config = {
    appRoot: __dirname
};

SwaggerExpress.create(config, (err, middleware) => {
    if (err) {
        throw err; // or handle error
    }
    middleware.register(app);

    const port = process.env.PORT || 10010;
    app.listen(port);
});

const swaggerSecurityHandlerCb = (err: Error) => {
    // do nothing
};

const configComplex: SwaggerExpress.Config = {
    appRoot: __dirname,
    configDir: "some/directory",
    controllersDirs: ["some/directory"],
    fittingsDirs: ["some/directory"],
    mockMode: true,
    swaggerControllerPipe: 'swagger_controllers',
    swaggerSecurityHandlers: {
        // did not manage to research the typings of first 3 arguments
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:swagger-express-mw-tests.ts


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